PDA

View Full Version : Command Button click



chungtinhlak
12-08-2008, 11:27 AM
Hello Again, I have a Form with 3 Command Buttons (this form will be use as a message box). In a module, I want to say that if i click choice 1, do the following. Choice 2, do this.... How do this "code the Click"....

here is the example code


Sub Executive_Update()
Dim Answer As String
Dim MyNote As String


MyNote = "Do you want to update the Executive File? (Warning: Only authorized personnel)"
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "???")
If Answer = vbNo Then
'Code for No button Press
Exit Sub
Else
UserForm2.Show
If UserForm2.cmddaily_Click Then
UserForm2.Unload
MsgBox (Daily)
End If
If UserForm2.cmdweekly = True Then
UserForm2.Unload
MsgBox (weekly)
End If
If UserForm2.cmdcancel = True Then
Exit Sub
End If


MsgBox ("Complete")
End If

End Sub

Bob Phillips
12-08-2008, 11:38 AM
Is the code that you show accurate, does it really show that you will open form, hide it in the form code, and then carry on. Assuming so, set a module public variable for each butoon in the form and test that.

chungtinhlak
12-08-2008, 11:45 AM
I don't get it....

Maybe it's not accurate, I can get the userform 2 to show, but in the module, I want those buttons on form2 to perform a particular task.

in the module, i want the Daily to first, exit form2 and perform some task, how to I say that in the module, because it's not take userform2.cmdexit_click = true?

I guess my question is how do it command a Click?

I don't even know what I'm saying anymore.
:)

thanks for you help XLD

nst1107
12-08-2008, 11:56 AM
Sounds like what you need to do is cut all the code you have in the If statment after "UserForm2.Show" and paste it in the respective _Click() events for each button of the userform.

nst1107
12-08-2008, 12:01 PM
For instance, you might paste this into the declarations area of UserForm2:

Private Sub cmddaily_Click()
Unload UserForm2
MsgBox (Daily)
End Sub
Private Sub cmdweekly_Click()
Unload UserForm2
MsgBox (weekly)
End Sub
Private Sub cmdcancel_Click()
Unload UserForm2
End Sub

chungtinhlak
12-08-2008, 12:30 PM
so i can only do the _Lick() within the form only????

chungtinhlak
12-08-2008, 02:01 PM
thank you, worked!
;)