How to prevent and event?

S

SMS

In a textbox.afterupdate() event, I have a line to make the
textbox.visible FALSE. This triggers another afterupdate event. How
do I suppress this?

Private Sub TextBox1_afterupdate()
TextBox1.Text = ""
TextBox1.Visible = False
End Sub

Thank you!
 
B

Bob Umlas

Private Sub TextBox1_afterupdate()
dim NotNow as boolean
If Notnow then exit sub
NotNow = true
TextBox1.Text = ""
TextBox1.Visible = False
NotNow = False
End Sub
 
P

Per Jessen

Hi

Turn off events before you manipulate the textbox, just remember to turn it
on again.

Private Sub TextBox1_afterupdate()
Application.EnableEvents=False
TextBox1.Text = ""
TextBox1.Visible = False
Application.EnableEvents=True
End Sub

Regards,
Per
 
B

Bob Umlas

That won't work -- events are not "events" as far as userforms are
concerned, and if you step thru the code you'll see it fires again. My
original code did have an error, however; the variable NotNow needs to be
dimmed at the top of the module, not inside the sub:

dim NotNow as boolean
Private Sub TextBox1_afterupdate()
If Notnow then exit sub
NotNow = true
TextBox1.Text = ""
TextBox1.Visible = False
NotNow = False
End Sub
 
S

SMS

Thanks for the workaround... it is interesting that events on a
userform are somehow different. I wonder if there is an easy way to
understand the descrepancies between the UFs and the standard sheets
wrt events.
 

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