Dynamic Creation of Combo boxes

Is there a way to set an event for the dynamically created combo boxes. For instance, when one of the combo boxes changes values, I want it call a function that will switch a global variable from false to true. That way, when I change student it will popup a message box saying some values have changed and ask if the user wants to save.
You would be looking to reading lines of code into the VBA editor and setting the BeforeUpdate method to "[Event Procedure]". If you're good with macros then it will be easier.

Just an after thought, can I have the form itself call that function when one of its combo boxes are updated?
Unfortunately, you can't. Form events apply to the form and not the controls within it.
 
Do you know how to set the macro in vba? The problem really is that I create and delete these combo boxes every time i open the form up, thus I have to be constantly resetting the event. I just am not sure how to edit the event.
 
I don't really use macros because I find them tedious so I can't help you with that unfortunately.:)

However, you could use an Expression instead. So an If block would be (for example):

=IIF([MyField] = 1, True Argument, False Argument)

Then you set the AfterUpdate method of the combo box to that expression.

Would be rather difficult to create if your original code is long.
 
I figured it out. I just set the BeforeUpdate value equal to the method I wanted to call. Works like a charm.

Code:
ctrlCombo.BeforeUpdate = "=Form_Updated()"

By the way, thanks to all of you for helping me out on this project. I know it seems like it shouldn't work at first, but you can now say that it works and you have the code to do it. Not sure how often you would use this idea, but it may come in handy some day. Again, thanks for past and probably future help!
 
You're welcome, glad you got it working.

These sort of things are useful if you had a Report Creating tool where users are given a list of fields which they can choose and a report is created based on their selections.
 

Users who are viewing this thread

Back
Top Bottom