Solved Call Public Sub from another Form by string (1 Viewer)

Saphirah

Active member
Local time
Today, 09:54
Joined
Apr 5, 2020
Messages
163
Hello everyone,

i am working on a quite general system that should be used in any form.
I have a popup form that can be opened on a lot of forms. This Popup form is a list where you can select values from.

When opening the form, the "target control" is saved as a public variable. This is the control where the selected value should be saved to after selecting an element from the list.
Code:
Public TargetControl As Control

Whenever the user selects something from the list, the value is written to that target control and the Form closes again.
Code:
TargetControl = Me.SelectedValue
DoCmd.CloseForm(Form.Name)

This works fine. But i do need to trigger the _AfterUpdate Event of the "TargetControl" manually, as this is not triggered when changing the value by code.
I could theoretically hard code every Update event.
But because the Popup form is used on various other forms, and will be used on more in the future, i need a generic way to call this update event.

I know of the "Run" function, and i tried something like this:
Code:
Run TargetControl.Parent.Name & "." & TargetControl.Name & "_AfterUpdate"
Which will result in
Code:
Run MyFormName.MyControlName_AfterUpdate
But this outputs a "Module not found" error.

So, my dear coding friends :D Can anyone help me with this problem?
How can i call the _AfterUpdate event of the "TargetControl" without hardcoding?

Thank you very much!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:54
Joined
May 7, 2009
Messages
19,170
make the AfterUpdate event of the Control as Public, ex:

Public textbox1_AfterUpdate()
'Some code here

End Sub


'''then adjust your code:
Code:
TargetControl = Me.SelectedValue
CallByName TargetControl.Parent, TargetControl.Name & "_AfterUpdate", vbMethod
DoCmd.CloseForm(Form.Name)
 

Saphirah

Active member
Local time
Today, 09:54
Joined
Apr 5, 2020
Messages
163
CallByName TargetControl.Parent, TargetControl.Name & "_AfterUpdate", vbMethod

This is exactly what i was looking for! Thank you very much arnel! Great vba as always! o_O:love:
 

Users who are viewing this thread

Top Bottom