Populate the name of the active control on focus in a form.

calvinle

Registered User.
Local time
Yesterday, 19:44
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
 
Hi. One event you could try to use is the controls GotFocus event.
 
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
 
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?"
 
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...
 
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
 
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?
 
Hi,

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

Thanks
 
create a public function.
add code:

public function fncFieldName() As String
fncFieldName = screen.activecontrol.controlsource
end function
 
Sorry typo
Private Function SomeFunction()
 
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.
 
do you have any code where you display/msg the controlname? can i have a peek?
 
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

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)>
 
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.
 
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:
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

and another one bite...
 

Attachments

I can't figure out why you want to do this. It would sure annoy me as a user.
 
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

Back
Top Bottom