suspend processing for TextBox_Change events when initializing a f

D

drhalter

I have a form with multiple textboxes. When initializing the form, I use
values from the worksheet to fill the textboxes. Each of these
initialization steps triggers the TextBox_Change event, which is unnecessary
during the initialization. Can I easily stop the TextBox_Change event during
this initialization?

The code following works, but seems a little bulky and I would prefer
something more efficient or eloquent. Oh, and it's a pain to have to write
the TextBox_Change code over and over for multiple textboxes.

What I have done is this (with x being a public variable):
x = false
....code that triggers Textbox_Change
x=true

Textbox_Change
If x = true then
....code
Else
'do nothing
End If

Thanks,
drhalter
 
J

Jon Peltier

That's basically what you have to do. I usually scope my variable to the
code module. I also call it bEnableEvents to mimic the
Application.EnableEvents property which doesn't affect UserForm events.

If you like, you could even use Application.EnableEvents, and do your
UserForm event procedures this way:

Private Sub Textbox1_Change()
If Application.EnableEvents Then
' your code goes here
End If
End Sub

- Jon
 
D

drhalter

Wow, that's a pain. I even have some code listed now
If x = true then
x = false
...code (which would trigger another TextBox_Change event, but
since x is false, it skips the code)
x = true
End If

Thanks for the info!
drhalter
 
J

Jon Peltier

Quick hint:

Instead of

If x = true then

you could simply use

If x then

- Jon
 

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