[ASAP] GotFocus event

P

Peter Schmitz

Hi,

in my current access vba project I have to set a textbox's '.text' property
to a specific value:

txtTest1.SetFocus
txtTest1.Text = ""

Now, when I run this code, the GotFocus handler of txtTest1 is called - how
can I prevent this? How can I erase a textbox's text property without calling
the GotFocus handler?

Thanks
Peter
 
B

Brendan Reynolds

Well, you can't. What you could do, though, is use a module level flag to
control whether code in the GotFocus event should run ...

mFlag = True
txtTest1.SetFocus
txtTest1.Text = ""

In the GotFocus event ...

If mFlag = True Then
mFlag = False
Exit Sub
End If

But why do you need to set the Text property? Is there a reason why you
can't set the Value property (which does not require that the control have
focus) instead of the Text property?
 
P

Peter Schmitz

Thanks for replying! All I want is to clear a textbox so that the user can
enter a new string. So, when I set value to "", does the textbox appear to be
empty?

Thanks
Peter
 
B

Brendan Reynolds

Yup! :)

--
Brendan Reynolds (MVP)


Peter Schmitz said:
Thanks for replying! All I want is to clear a textbox so that the user can
enter a new string. So, when I set value to "", does the textbox appear to
be
empty?

Thanks
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top