![]() |
suspend processing for TextBox_Change events when initializing a f
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 |
suspend processing for TextBox_Change events when initializing a f
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 ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech.com _______ "drhalter" wrote in message ... 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 |
suspend processing for TextBox_Change events when initializing
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 "Jon Peltier" wrote: 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 ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech.com _______ "drhalter" wrote in message ... 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 |
suspend processing for TextBox_Change events when initializing
Quick hint:
Instead of If x = true then you could simply use If x then - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech.com _______ "drhalter" wrote in message ... 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 "Jon Peltier" wrote: 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 ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech.com _______ "drhalter" wrote in message ... 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 |
All times are GMT +1. The time now is 09:57 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com