Can someone give me the script for simple OK/cancel buttons on a form? With the focus on the OK button like Windows? That would be awesome!! Thanks!!
~Brian
Printable View
Can someone give me the script for simple OK/cancel buttons on a form? With the focus on the OK button like Windows? That would be awesome!! Thanks!!
~Brian
Draw two buttons on the form. Name on cmdOK and the other cmdCancel.
Make the caption on cmdOK "&OK" and change the default property to "True".
Make the caption on cmdCancel "&Cancel".
Then place the statement Unload Me in cmdCancel.
Code:Private Sub cmdCancel_Click()
'Unloads the Form
Unload Me
End Sub
Also if you set the Cancel property to True for the Cancel button the user can press the Escape key and the Click event will be raised.
'<< or >>
Code:'a command button called Quit
Private Sub Quit_Click()
Dim lResult As Long
lResult = (MsgBox("Do You Really Want To Quit?", vbYesNo, "Quit Application"))
If lResult = 6 Then
Dim Form As Form
For Each Form In Forms
Unload Form
Set Form = Nothing
Next Form
Else
Exit Sub 'or whatever you want to do
End If
End Sub