Microsoft Office Tutorials and References
In Depth Information
Making Decisions in VBA Code
Figure 3-5:
Option
group and
button on a
form.
In the class module for that form, a sub procedure named OKButton_
Click() executes whenever someone clicks OK. The sub procedure, shown
in Figure 3-6, opens a form, exits Access, or does nothing, depending on
what’s selected in the WhereTo option group.
Figure 3-6:
Sub
procedure to
handle OK
Button_
click() .
The OKButton_Click() procedure does its job this way. When the
procedure is called, the following statement executes first:
Select Case Me!WhereTo.Value
This statement uses the Me!WhereTo.Value expression to refer to the
value of the WhereTo option group on the form. The word Me! is used
mainly in class modules to refer to the form or report to which the class
module is attached. Me!WhereTo.Value is a number from 1 through 5
when the code executes. If no option is selected, Me!WhereTo.Value
equals Null. In that case, the code after the Case Else statement executes.
If you omit the Case Else statement from the sample code, no code within
the Select Case...End Case block executes when Me!WhereTo.Value
contains something other than a number from 1 through 5. Execution
continues normally at the first line after the End Case statement, however.
Search JabSto ::




Custom Search