Microsoft Office Tutorials and References
In Depth Information
Opening Forms with DoCmd
Listing 4-2: Message-Box Response Code in Which a Numeric Value
Refers to myVar
‘Show a message box with Yes and No buttons.
Dim myVar as Byte
myVar = MsgBox(“Are you sure?”,vbYesNo+vbQuestion)
‘Decide what to do next based on button clicked in box.
If myVar = 6 Then
Do these statements if Yes
Else
Do these statements if No
End If
If you need three buttons, you can use a Select Case statement to choose
what to do. The code in Listing 4-3 displays a message box with Yes, No, and
Cancel buttons. The Select Case block of code decides what to do based
on the button that was clicked. (Again, Do these statements represents
any number of VBA statements.)
Listing 4-3: Message-Box Response Code for Three Buttons
‘Show a message box with Yes, No, and Cancel buttons.
Dim myVar as Byte
myVar = MsgBox(“Overwrite?”,vbYesNoCancel+vbQuestion)
‘Decide what to do next based on button clicked in box.
Select Case myVar
Case vbYes
Do these statements if Yes clicked
Case vbNo
Do these statements if No clicked
Case vbCancel
Do these statements if Cancel clicked
End Select
Message boxes are handy for presenting short messages or asking the user
questions. Often, though, you want your code to open an entire form.
Opening Forms with DoCmd
Although you can access countless objects in VBA, the DoCmd object (pro-
nounced do command) is one of the easiest and handiest for manipulating
Access objects. The DoCmd object gives you access to all the commands —
including options on all menus, Ribbon groups, and shortcut menus — in the
Access program window. The basic syntax of a DoCmd statement is as follows:
DoCmd. methodName arglist )
methodName is any method that’s supported by the DoCmd object, and
arglist represents required and optional arguments that a given method
accepts.
 
Search JabSto ::




Custom Search