Call Command_Click

Local time
Today, 09:32
Joined
Dec 18, 2024
Messages
13
Can someone advice me on how to run the Command405_Click button that's on the (Parent form) from the (child Subform) using a Command330 button?
 
Firstly give your controls meaninful names. Command405 is not going to mean anything to you or anyone else 6 montns down the road. :(
Most developers do not recommend calling control events directly.

Create a common sub and call it from your both your command buttons.
 
FWIW ChatGPT shows
Code:
Private Sub cmdSubButton_Click()
    ' Call the main form's command button click event
    Call Forms!frmMain.cmdMainButton_Click
End Sub

I would have tried with Me.Parent.cmdMainButton_Click
 
FWIW ChatGPT shows
Code:
Private Sub cmdSubButton_Click()
    ' Call the main form's command button click event
    Call Forms!frmMain.cmdMainButton_Click
End Sub

I would have tried with Me.Parent.cmdMainButton_Click
I tried calling the command button directly, but it doesn't work.
 
By default Event Procedures are Private so even if you get the syntax correct it will not work. You would have to change to public and then do what @Gasman suggests. However, as he mentioned it is cleaner to break it off into a stand alone procedure that the click event calls and then the subform can call
 
T
By default Event Procedures are Private so even if you get the syntax correct it will not work. You would have to change to public and then do what @Gasman suggests. However, as he mentioned it is cleaner to break it off into a stand alone procedure that the click event calls and then the subform can call
That worked!!! Thanks : )
 
Please take the EXPERT advice to NOT call the procedure directly. Move the code to a standard module and call it from every place you want to use it. You can thank us for that advice later. Or not because if you follow the advice, you won't ever run into a problem. For now, rename your controls.
 

Users who are viewing this thread

Back
Top Bottom