Populate the name of the active control on focus in a form. (1 Viewer)

calvinle

Registered User.
Local time
Today, 05:23
Joined
Sep 26, 2014
Messages
332
Hi,

I have a form with many field and I would like to know if it's possible to populate the name of that field once we click on that field?

Is there any fire event that capture each time we navigate through different field?

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:23
Joined
Oct 29, 2018
Messages
21,358
Hi. One event you could try to use is the controls GotFocus event.
 

calvinle

Registered User.
Local time
Today, 05:23
Joined
Sep 26, 2014
Messages
332
Yes, but I have to set the function to populate the field name on each of the field. Isn’t there an event on the form itself that detects each time we move between field?

Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:23
Joined
Oct 29, 2018
Messages
21,358
Yes, but I have to set the function to populate the field name on each of the field. Isn’t there an event on the form itself that detects each time we move between field?

Thanks
Hi. Nothing that I am aware of. What do you mean by "populate the field name on each of the field?"
 

calvinle

Registered User.
Local time
Today, 05:23
Joined
Sep 26, 2014
Messages
332
In a continuous form, I can write:
[control].[Form]![field name] then it will populate that field.

On a single form, I have multiple field on the firm. I want the form to prompt the name of the field I am currently in. Once I go to another field, it will prompt the name of the field.

Example prompt:
You are in emp_id.
You are in hr_name.

Etc...
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:23
Joined
May 21, 2018
Messages
8,463
If you make a single function

Public SomeFunction()
msgbox activecontrol.name
end function

Then in design view select all the textboxes you want.
In the gotfocus event type
=SomeFunction()

all controls react to the same function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:23
Joined
Oct 29, 2018
Messages
21,358
In a continuous form, I can write:
[control].[Form]![field name] then it will populate that field.

On a single form, I have multiple field on the firm. I want the form to prompt the name of the field I am currently in. Once I go to another field, it will prompt the name of the field.

Example prompt:
You are in emp_id.
You are in hr_name.

Etc...
Hi. Would MajP's suggestion work for you?
 

calvinle

Registered User.
Local time
Today, 05:23
Joined
Sep 26, 2014
Messages
332
Hi,

Nope it does not. I get error message:
The expression you entered has a function containing the wrong number of arguments.

Thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:23
Joined
May 7, 2009
Messages
19,175
create a public function.
add code:

public function fncFieldName() As String
fncFieldName = screen.activecontrol.controlsource
end function
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:23
Joined
May 21, 2018
Messages
8,463
Sorry typo
Private Function SomeFunction()
 

calvinle

Registered User.
Local time
Today, 05:23
Joined
Sep 26, 2014
Messages
332
create a public function.
add code:

public function fncFieldName() As String
fncFieldName = screen.activecontrol.controlsource
end function

Thanks this works, but I forgot to mention that the field is in a subform. The code works when I open the subform by itself but when its in a form as subform, the active capture the form as active form, so it doesnt work.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:23
Joined
May 7, 2009
Messages
19,175
do you have any code where you display/msg the controlname? can i have a peek?
 

calvinle

Registered User.
Local time
Today, 05:23
Joined
Sep 26, 2014
Messages
332
Hi,

I have attached an example of what I am trying to achieve.
If you open the "client_subfrm", and click on any field, the "Hint" will lookup in the table for hint, but if you open the main form which is supplier_frm, it won't work.

Can you take a look.

Thanks
 

Attachments

  • Test.accdb
    504 KB · Views: 56

missinglinq

AWF VIP
Local time
Today, 08:23
Joined
Jun 20, 2003
Messages
6,423
You could display each Control's name (or anything else you'd like) in the Control itself, when the Record loads, by, in each Control's Format Property, simply entering the name, or whatever, like this

@;"Your Prompt Goes Here"

The name or prompt will disappear when Control is entered...reappear when Control is left, if no data has been entered. Also, if no data is entered...the field bound to the Control remains Null.

Linq ;0)>
 

calvinle

Registered User.
Local time
Today, 05:23
Joined
Sep 26, 2014
Messages
332
You could display each Control's name (or anything else you'd like) in the Control itself, when the Record loads, by, in each Control's Format Property, simply entering the name, or whatever, like this

@;"Your Prompt Goes Here"

The name or prompt will disappear when Control is entered...reappear when Control is left, if no data has been entered. Also, if no data is entered...the field bound to the Control remains Null.

Linq ;0)>

Right but I want to display an hint by using a dlookup from a table (see my attachment). In the futur, if there is changes in the hint, they can simply change in the table without the need to throw out a new version of the front end.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:23
Joined
May 21, 2018
Messages
8,463
Code:
Public Function DisplayHint() As String
On Error Resume Next
  DisplayHint = Screen.ActiveControl.Name
  Screen.ActiveControl.Parent.txtHint.Value = DLookup("field_hint", "field_t", "field_name = """ & DisplayHint & """")
End Function

Works for me.
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 05:23
Joined
Oct 29, 2018
Messages
21,358
Thanks this works, but I forgot to mention that the field is in a subform. The code works when I open the subform by itself but when its in a form as subform, the active capture the form as active form, so it doesnt work.
Hi. Try the attached modified version. It's just one of many ways to do the same thing.
 

Attachments

  • Test(1).zip
    27.8 KB · Views: 43

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:23
Joined
May 7, 2009
Messages
19,175
and another one bite...
 

Attachments

  • Test (4).zip
    50.9 KB · Views: 48

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:23
Joined
Feb 19, 2002
Messages
42,981
I can't figure out why you want to do this. It would sure annoy me as a user.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:23
Joined
Feb 28, 2001
Messages
27,001
Instead of all of this, put something in the "ToolTip" property, so that if you hover over the control, you get a one-line explanation. I understand what you want to do, but because of sub-form complications you are giving yourself a LOT of work for a benefit of limited scope. I'm kind of with Pat on this. Do too much and you annoy the heck out of the user. Trust me, I understand that it is a "damned if you do, damned if you don't" situation.
 

Users who are viewing this thread

Top Bottom