command button selects another

tubar

Registered User.
Local time
Today, 17:01
Joined
Jul 13, 2006
Messages
190
is there a way to creat a on click event for a comand button that clicks another command button...example by clicking command button 1 it automatically clicks command button 2
 
Don't know why you don't just click button 2 but.....

Code:
Private Sub Button1_Click()
  Button2_Click
End Sub
 
I'm not sure if you can actually raise the event of a command button click but you can certainly call the procedure that that click would run. So if a FormA has a button click handler like ...
Code:
Private Sub Command0_Click()
  MsgBox "Clicked FormA.Command0"
End Sub
...then you can change it to ....
Code:
[COLOR="DarkRed"]Public[/COLOR] Sub Command0_Click()
  MsgBox "Clicked FormA.Command0"
End Sub
...and run it from FormB using ...
Code:
Private Sub Command0_Click()
  Forms("FormA").Command0_Click
End Sub
But better design might entail that if you have a process that needs to be invoked by a variety of consumers, make that process public such that button clicks call that process ...
Code:
[COLOR="Green"]'in a standard module[/COLOR]
Public Sub MyGenericProcess
  'do something here that could be used in multiple places
End Sub
---
[COLOR="Green"]'on FormA[/COLOR]
Private Sub Command0_Click()
  MyGenericProcess
End Sub
---
[COLOR="Green"]'on FormB[/COLOR]
Private Sub Command0_Click()
  MyGenericProcess
End Sub
Cheers,
Mark
 
I'm not sure if you can actually raise the event of a command button click

the command route can be called as it is nothing more than another routine name. you can call any form routine (including command button ones) by using this method-

Code:
Form_frmMyForm.cmdMyButton_Click

the use of
Code:
Form_frmMyForm.
points to the forms code followed by the routine name

HTH


Nigel
 
just what David said in #2
though it will run the code as button2 was clicked it won't click the button.
 

Users who are viewing this thread

Back
Top Bottom