Databases Reference
In-Depth Information
To help simplify the exposition, we will follow Microsoft's lead and use square brackets
to indicate optional parameters. Thus, for instance, the second parameter in the following
procedure is optional:
Sub ChangeFieldType(
sFieldName
, [
NewSize
])
Note that we have also omitted the data type declarations, which will be discussed
separately.
12.1 The MsgBox Function
We have been using the
MsgBox
function unofficially for some time now. Let us
introduce it officially. The
MsgBox
function is used to display a message and wait for the
user to respond by pushing a button. The most commonly used syntax is:
MsgBox(
prompt
[,
buttons
] [,
title
])
(This is not the function's complete syntax. There are some additional optional
parameters related to help contexts that you can look up in the help documentation.)
prompt
is a String parameter containing the message to be displayed in the dialog box.
Note that a multiline message can be created by interspersing the
vbCrLf
constant within
the message.
buttons
is a Long parameter giving the sum of values that specify various properties of
the message box. These properties are the number and type of buttons to display, the icon
style to use, the identity of the default button, and the modality of the message box. (A
system modal
dialog box remains on top of all currently open windows and captures the
input focus systemwide, whereas an
application modal
dialog box remains on top of the
application's windows only and captures the application's focus.) The various values of
buttons
that we can sum are shown in Table 12-3. (They are officially defined in the
VbMsgBoxStyle
enum.)
Table 12-3. The M
s
gBox b
u
ttons argument values
Purpose
Constant
Value
Description
B
utton types
v
bOKOnly
0
D
isplay OK button only
vbOKCancel
1
Display OK and Cancel buttons
v
bAbortRetryIgnore
2
D
isplay Abort, Retry, and Ignore buttons
vbYesNoCancel
3
Display Yes, No, and Cancel buttons
v
bYesNo
4
D
isplay Yes and No buttons
vbRetryCancel
5
Display Retry and Cancel buttons
I
con types
v
bCritical
16
D
isplay Critical Message icon
vbQuestion
32
Display Warning Query icon
v
bExclamation
48
D
isplay Warning Message icon
vbInformation
64
Display Information Message icon
D
efault button
v
bDefaultButton1
0
F
irst button is default