"On Got Focus" Question

NoSmoke

Registered User.
Local time
Yesterday, 21:00
Joined
Nov 10, 2012
Messages
99
I thought this would work but it doesn't - would appreciate any assistance.

If one has text boxes or combo boxes on a form and wishes certain text to appear in a box when the box gets focus, how is this done?

I have tried placing (for example) ="123" in the On Got Focus property of the box thinking 123 would appear in the box whenever the cursor was moved to it. However, nothing happens.

Can anyone please tell me the correct way of doing it?

TIA...
 
The Got Focus event should do what you are after, but I would us something along the lines of;
Code:
If IsNull(Me.YourField) Then
     Me.YourField = "Your Text"
End If
As simply using;
Code:
Me.YourField = "Your Text"
Will result in the text that already exists in that field to be over written, every time your user tabs into the field.

However rather than hard coding this why not set your Text as the Default Value for the field :confused:
 
John, it works fine (the first suggestion) and thank you!

The reason I'm not using Default Value is that I wish the user to have to actively select contents for the field(s) by clicking or tabbing to it. If they don't do that, it should remain blank. If they do click or tab, they can keep the "Your Text" value or modify it.

I'm curious though why, if you delete out an entry in the field and click or tab back to it, it still enters the "Your Text" value. I did not expect that as I thought IsNull pertained only to a field that had never had anything entered before.

Also, I have dozens of these fields and was wondering if there is a way to reuse the same copy of the code for each of them (with different "Your Text" as an argument? if possible)? Or, maybe better, let it enter the first value in the combo box pull-down list(?).

Thanks again......
 
Last edited:
IsNull relates to any Null field, perhaps you are thinking of the NewRecord property?

You could create public function

Also you might want to modify the code slightly to pick up ZLS;
Code:
If IsNull(Me.YourField) or Me.YourField = "" Then
     Me.YourField = "Your Text"
End If
 
It doesn't offend people if you make mention of it in both posts. That way, we don't work to solve your problem if you already have an answer. So, in the future, as a courtesy to those who are helping you, mention the multiple post and provide links.

OK, fair 'nuff.

Thanks...
 

Users who are viewing this thread

Back
Top Bottom