Tuesday, January 6, 2009

Triggering an Event via VB Code - Name of event = string, ie dynamic

Lets say you're using a calendar control to populate a text box. (I recommend Allen Browns version). You set it up and everything works just fine, however you want the afterUpdate event to trigger after the calendar form updates the textbox value. Because the value is updated via code (visual basic) the event does not trigger.

I've researched for quite awhile trying to figure out how to make it trigger but I couldn't find a solution - raiseEvent? Seems to have something more to do with creating a new class with events and then raising them (dim withEvents aControl new control - never used this before).

callByName - they seems like a possibility but couldn't figure it out.

Eval (eventname as text) didn't work.

The only solution (that is NOT really dynamic) that works is a case or if statement that says if the control.name = the control name that has the event that I want to trigger then [call] thatControls_actualEventName.

Please note that the event (sub procedure) that you want to call from another form possible must then be a public sub (or function) instead of a private sub (or function)

Any better solutions - actual dynamic solutions?