msgbox isn't working for me

  • Thread starter Thread starter Bomber
  • Start date Start date
B

Bomber

Hi all,

should this be working for me ?

MsgBox(Success, 64, Update)

I get a Compile Error, expected: =

Any ideas ?

cheers,

Adam
 
First, the arguments you specify as Success and Update should be strings. I
assume they are not variable names, so they should be specified as "Success"
and "Update" (including the quotes).

Second, MsgBox is a function that returns a result. It can be called as a
Sub if you want to ignore the result, but this must be done differently,
either using Call or omitting the parentheses:

To save the returned result (only necessary if you have more than one
button:
VariableName = MsgBox("Success", 64, "Update")

To ignore the result, either:
Call MsgBox("Success", 64, "Update")
or:
MsgBox "Success", 64, "Update"

Note that in the last case, the parentheses are omitted.

Also, the second argument, 64, indicates that the message box should display
the "i" information icon. 64 means nothing to someone reading your code, so
it would be better to use the built-in constant that is provided for the
purpose:
MsgBox "Success", vbInformation, "Update"

Or, even better, to indicate which buttons are displayed:
MsgBox "Success", vbOKOnly + vbInformation, "Update"
 
Thanks Graham :)

Graham Mandeno said:
First, the arguments you specify as Success and Update should be strings. I
assume they are not variable names, so they should be specified as "Success"
and "Update" (including the quotes).

Second, MsgBox is a function that returns a result. It can be called as a
Sub if you want to ignore the result, but this must be done differently,
either using Call or omitting the parentheses:

To save the returned result (only necessary if you have more than one
button:
VariableName = MsgBox("Success", 64, "Update")

To ignore the result, either:
Call MsgBox("Success", 64, "Update")
or:
MsgBox "Success", 64, "Update"

Note that in the last case, the parentheses are omitted.

Also, the second argument, 64, indicates that the message box should display
the "i" information icon. 64 means nothing to someone reading your code, so
it would be better to use the built-in constant that is provided for the
purpose:
MsgBox "Success", vbInformation, "Update"

Or, even better, to indicate which buttons are displayed:
MsgBox "Success", vbOKOnly + vbInformation, "Update"

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Bomber said:
Hi all,

should this be working for me ?

MsgBox(Success, 64, Update)

I get a Compile Error, expected: =

Any ideas ?

cheers,

Adam
 
Hi all,

should this be working for me ?

MsgBox(Success, 64, Update)

I get a Compile Error, expected: =

Any ideas ?

cheers,

Adam

Assuming that Success and Update are text string variables that have
been defined, there are two ways to use MsgBox:

1. As a command, e.g.

MsgBox Success, 64, Update

2. As a Function which returns a value:

Dim iAns As Integer
iAns = MsgBox(Success, vbYesNo)
If iAns = vbYes Then
...
 
Back
Top