HandsOn Returning Values from the Msg Box Function

1. In the Visual Basic Editor window, choose Insert | Module to add a new module.

2. In the Code window, enter the code of the MsgYesNo3 procedure as shown below.

Sub MsgYesNo3()

Dim question As String Dim myButtons As Integer Dim myTitle As String Dim myChoice As Integer question = "Do you want to open a new report?" myButtons = vbYesNo + vbQuestion + vbDefaultButton2 myTitle = "New report"

myChoice = MsgBox(question, myButtons, myTitle) MsgBox myChoice End Sub

In the above procedure, you assigned the result of the MsgBox function to the variable myChoice. Notice that the arguments of the MsgBox function are now listed in parentheses:

myChoice = MsgBox(question, myButtons, myTitle)

Introduction to Access 2003 VBA Programming

0 0

Post a comment