How can I call a click procedure of a command button from another form?
Printable View
How can I call a click procedure of a command button from another form?
u cannot call a click procedure of a button of another form because it is private to that form. u can do one thing. create a public procedure in your start up module. And you can call that procedure from any form.
hope this will solve your problem
regards,
prakash
You don't necessairly have to put a sub in a module. You can make a Public sub on a form. If the sub on the form is Public, it can be called from another form.
can we declare a public sub in the form? i am not sure!!
Create Public Sub in the form with the click event...
Public Sub RunClick()
CommandButton1_Click
End Sub
The call this from wherever it is needed..
MyForm.RunClick
An easier alternative is to simply use the following..
MyForm.CommandButton1.Value = True
This will run the click event of commandbutton1 and does not require any extra subs...
Calling click events from buttons of any sort on a different form poses a problem in that all click events are Private to the form. It is better to create a Public sub on the form. That can be accessed easily.
Yes, but all controls on a form are available...
So are there properties...
Setting the value property of a command button to true fires its click event...
You are correct providing the button resides on the same form that is doing the calling. :)Quote:
Originally posted by Leather
Setting the value property of a command button to true fires its click event...
NO NO NO not true. Try thisQuote:
Originally posted by Hack
You are correct providing the button resides on the same form that is doing the calling. :)
form1Form2VB Code:
Option Explicit Private Sub Command1_Click() Form2.cmdTest.Value = True End SubVB Code:
Option Explicit Private Sub cmdTest_Click() MsgBox "Form2" End Sub