I’m new to VB (using VBA, actually) and I would like to force an event to fire. Specifically, I am updating the value in a textbox and I would like to call that textbox’s AfterUpdate() event.
Private Sub cmdCreateInvoice_Click()
Me.txtInvDate = '11/01/10'
Me.txtInvDate.AfterUpdate
End Sub
During run time, I get an error that says “Compile Error: Invalid Use of Property”. If I try something similar, but with the click event (ex: cmdCreateInvoice.Click), which does NOT have a property that shares the name, I get an error that says “Compile Error: Method or Data member not found”.
I know there must be a way to fire one event from another. But what is the proper syntax?
Thanks!
AFAIK, there is no way to “fire an event manually” in VB(A). What you can do is call the event handler manually, and for this, rdkleine has given you the answer already:
This will have exactly the same effect as if the event had fired (though it does not give you the whole chain of events that may also fire along with it–unless you
Calltheir handlers as well).IgorM has another valid point, in comments on his answer–it’s “cleaner” to write a different Sub to do the work you want done, then call it from both the event handler & wherever you’re trying to do it now (button click?). So:
You could even make
DoWhatevera Public Sub in a Module.Edit
And no, in VB(A) it doesn’t matter what order you define your Sub (or Function) routines.