[RESOLVED] Not call _Change() functions
Hey there,
I'm sure this has been asked before, but I was unable to find an answer... I have a combobox on a form that's properties gets initialized in the UserForm_Init method... However, the combobox also has a _Change() method, but I don't want that Change method to be called in the init method of the userForm...
Is there a way to specify this in either the init or change methods?
thanks much,
Paul
Re: Not call _Change() functions
Quote:
I don't want that Change method to be called in the init method of the userForm...
but then the _Change() is as it is not called in the UserForm_Init method
What is the code in the UserForm_Init ? I mean what properties are you trying to initialize in the UserForm_Init for the combo?
Re: Not call _Change() functions
hey paul
whenever i have to deal with this i implement a "flag" of sorts to tell whether or not to do the actions. sometimes i make the flag global, otherwise just modular (depending on the scope needed).
i implement it as follows
1) dim it wherever you want (so the scope is correct)
2) set it to "False" as the first step in the UF_Init routine
3) do all the uf initialization
4) set it to true when exiting the UF_init routine
then, in any "Change" or similar event, just check if your boolean flag is true or false. true - do the change event code. false - just exit
hth :)
Re: Not call _Change() functions
Well, in the UserForm_Init, I change the text of the combo box.. doesn't changing that text call the change() method of that combo box?
because during init I don't want the change method to be called, as it looks something up in a table that shouldn't be done at that point.
Re: Not call _Change() functions
Quote:
Originally Posted by vwgtir32vr6
hey paul
whenever i have to deal with this i implement a "flag" of sorts to tell whether or not to do the actions. sometimes i make the flag global, otherwise just modular (depending on the scope needed).
i implement it as follows
1) dim it wherever you want (so the scope is correct)
2) set it to "False" as the first step in the UF_Init routine
3) do all the uf initialization
4) set it to true when exiting the UF_init routine
then, in any "Change" or similar event, just check if your boolean flag is true or false. true - do the change event code. false - just exit
hth :)
ah great... was hoping there might just be a vba command to ignore change methods, but implementing these booleans shouldn't be too tricky. thanks much
Re: [RESOLVED] Not call _Change() functions
Quote:
Well, in the UserForm_Init, I change the text of the combo box
Ah no wonder...
Just a question, why not prefeed the text of the combobox in design mode and set rest of the properties in the init() code? that will save you lots of coding....
Re: [RESOLVED] Not call _Change() functions
Well, it's not always the same... I read the text from a file.
Re: [RESOLVED] Not call _Change() functions
ya, that command would be nice, but as far as i know it doesn't exist... oh well.
koolsid, that is a good idea, but as is the case with most of my projects, the text for my comboboxes and listviews is "discovered" as part of the init routine (x and y variables on the active worksheet, for instance). in that case, i can't prefeed the text. i see your point though.
Re: [RESOLVED] Not call _Change() functions
Quote:
Well, it's not always the same... I read the text from a file.
In that case, yes, using a flag as vwgtir32vr6 suggested is apt.
Also on second thoughts, here is another way I'd do it...
Keep the text constant. Now my question would be what text should i set in design mode so that it is constant everytime??? something like "Please select your option" and in the init() event I simply add items to the combobox??? ..... additem doesn't fire the change() event :)
It is just a thought...
your views guys...
Re: [RESOLVED] Not call _Change() functions
yes that would work. i have never considered that because i am a little surprised that the .AddItem does not fire the change event. that would work good also it sounds like. i tend to prefer the flag approach because it is very easy to handle whatever event you have to deal with and it is simple to code. as is usually the case, there are a million ways to accomplish this task though... :)
Re: [RESOLVED] Not call _Change() functions
it doesn't...
try this
place a combo on a userform and then use this code. now run the userform. you will see that the change code is not fired....
Code:
Private Sub ComboBox1_Change()
MsgBox "hello"
End Sub
Private Sub UserForm_Initialize()
ComboBox1.AddItem "aaaa"
End Sub
Re: [RESOLVED] Not call _Change() functions
that's a good point sid... but in one of my combo box's there are about 300 items, so the whole point of automatically changing the text of the combo box was so that the user didn't have to tediously select their input.
still overall, a little odd that MS doesn't at least offer some sort of way to bypass the change events...
Re: [RESOLVED] Not call _Change() functions
Quote:
.... about 300 items...
Since we are having an intelligent conversation... I have one more point to add...
I am sure that you are aware that the combobox autocompletes as you type??? so selecting your choice from a 300 or 500 entries is not a problem... what say?
Re: [RESOLVED] Not call _Change() functions
Hah yeah that is true...
But the program itself has about 100 inputs with about 15 combo boxes and 5 forms... so if a user progresses through all the screens and decides to save the input/output, then they can open that file again and all the inputs are opened in the screens... saving the user from remembering what they even input. Before each form is displayed, if a file was opened, those inputs are brought into the form during the init, however, as I learned that was throwing the change() code, which would actually change their inputs to default numbers (as I have the change() code structured).
I just implemented the modular boolean flags, and they are working great!
So I guess in this situation, the flags were the only way to do it... basically for ease of use of the user!