Calling a Public sub "By Reference"

  • Thread starter Thread starter Jon Lewis
  • Start date Start date
J

Jon Lewis

I'm passing a fully qualified object parameter (TextBoxMV As TextBox) to a
procedure in a standard module:

MyPublicSub Forms!myForm!myTextBox

I need the sub to call the TextBox's After Update event at some stage (I've
obviously made the event Public in its Form's Class Module).
Can someone help with the syntax please?

I've tried various permutations using the object, Parent, Name ect to no
avail.

"Forms!" & TextBoxMV.Parent.Name & "!" & TextBoxMV.Name & "_AfterUpdate"
forms the correct string but how do I convert this to a procedure call

Many TIA

Jon
 
The AfterUpdate event is specifically for performing an action when a control
has been updated and you shouldn't mess with it.

If you have code in that event that you want to call from elsewhere, you
should place that code in another procedure and call that procedure from your
AfterUpdate event and any other external/internal process.

Steve
 
Jon, if the form is named frmMain and the textbox is named txtBubba,
try calling form_frmMain.txtBubba_AfterUpdate

UpRider
 
I Disagree & do it a lot (mainly in the forms scope albeit)

Call Forms("MyForm").AfterUpdate is one way
Call Forms_MyForm.AfterUpdate should work too

Pieter
 
Thanks for your reply

The event procedure will only be called when the textbox is updated. What
I'm trying to do is similar to what a custom combo would be. A combo's
after update occurs when a new dropdown choice is made (even though focus
remains on the textbox part) unlike a stand alone text box where focus has
to leave the control. However if the combo is updated by VBA the event does
not fire at all.

My procedure (which I will be wrapping up in a Class Object) will have an
additional boolean parameter which when true will have the procedure call
the After Update for the textbox if the procedure does update the textbox's
value.

So I need a generic way of calling a textbox's After Update event. Even if
I do what you suggest, I would have to create a seperate procedure for each
TextBox's AfterUpdate (as the procedures could be different) so would still
need to call such a procedure with reference to the textbox.

Call "Forms!" & TextBoxMV.Parent.Name & "!" &
"CustomAfterUpdateforTextBoxMV.Name " or whatever the syntax would be which
it what I'm trying to get help with.

Jon
 
Thanks for your suggestion Uprider but I need to call the procedure relative
to a passed TextBox object variable.

Call TextBoxMV.Name_AfterUpdate if that would work (which it doesn't!)

Jon
 
Solution:

CallByName TextBoxMV.Parent, TextBoxMV.Name & "_AfterUpdate", VbMethod

Jon

"Pieter Wijnen"
 
Back
Top