Msgbox Code Syntax Error

  • Thread starter Thread starter Pamela
  • Start date Start date
P

Pamela

I have a message box that I want to display in the OnEnter event of a List
box simply to give instructions as to how the user is to enter the info. My
code for the Message box isn't working and I'm getting a syntax error - I
also got an error that the system is expecting an "=" in the code. I've
researched it but can seem to see what I'm missing. I only want an OK button
on it and then to return focus to to the control to which the code is
attached. Here's the code:
Private Sub lbDamagedParts_Enter()
Me!Label23.Visible = True
Msgbox("For the following sections: (Chr(13))Damaged Parts, Unrelated Prior
and Supp Items (Chr(13)) Select all that apply by holding as you click to
select or unselect multiple entries",vbokonly,"Warning")
End Sub
Thanks so much!!
Pamela
 
Hi Pamela,
There are 2 MsgBox commands. One is a function, the other a statement.

You need the statement form.

Msgbox "For the following sections: (Chr(13))Damaged Parts, Unrelated
Prior
and Supp Items (Chr(13)) Select all that apply by holding as you click
to
select or unselect multiple entries",vbokonly,"Warning"

A function requires the = because it assigns a reply to a variable.
Response = MsgBox (parameters)

A statement just says "Show This"
MsgBox parameter, parameter ...
--
Len
______________________________________________________
remove nothing for valid email address.
|I have a message box that I want to display in the OnEnter event of a
List
| box simply to give instructions as to how the user is to enter the
info. My
| code for the Message box isn't working and I'm getting a syntax error -
I
| also got an error that the system is expecting an "=" in the code.
I've
| researched it but can seem to see what I'm missing. I only want an OK
button
| on it and then to return focus to to the control to which the code is
| attached. Here's the code:
| Private Sub lbDamagedParts_Enter()
| Me!Label23.Visible = True
| Msgbox("For the following sections: (Chr(13))Damaged Parts, Unrelated
Prior
| and Supp Items (Chr(13)) Select all that apply by holding as you click
to
| select or unselect multiple entries",vbokonly,"Warning")
| End Sub
| Thanks so much!!
| Pamela
|
 
I have a message box that I want to display in the OnEnter event of a List
box simply to give instructions as to how the user is to enter the info. My
code for the Message box isn't working and I'm getting a syntax error - I
also got an error that the system is expecting an "=" in the code. I've
researched it but can seem to see what I'm missing. I only want an OK button
on it and then to return focus to to the control to which the code is
attached. Here's the code:
Private Sub lbDamagedParts_Enter()
Me!Label23.Visible = True
Msgbox("For the following sections: (Chr(13))Damaged Parts, Unrelated Prior
and Supp Items (Chr(13)) Select all that apply by holding as you click to
select or unselect multiple entries",vbokonly,"Warning")
End Sub
Thanks so much!!
Pamela

There are two ways to use MsgBox. One is as a statement which does not return
a value:

MsgBox "Message", <optional operands>

The other is a function, which does:

iAns = MsgBox("Message", <optional operands>)

Since in this case you don't want the user to reply with Yes or No, try using
the statement syntax. I'm also correcting the use of Chr(13) - carriage return
- to Chr(13) & Chr(10) - carriage-return-line-feed, and some quote errors:

Msgbox "For the following sections:" & Chr(13) & Chr(10) & _
"Damaged Parts, Unrelated Prior and Supp Items" & Chr(13) & Chr(10) & _
"Select all that apply by holding as you click to select " & _
"or unselect multiple entries",vbokonly,"Warning"
 
Hi John,
Any reason you used Chr(13) & Chr(10) rather than vbCrLf?
--
Len
______________________________________________________
remove nothing for valid email address.
| On Sun, 3 Jan 2010 21:06:01 -0800, Pamela
<[email protected]>
| wrote:
|
| >I have a message box that I want to display in the OnEnter event of a
List
| >box simply to give instructions as to how the user is to enter the
info. My
| >code for the Message box isn't working and I'm getting a syntax
error - I
| >also got an error that the system is expecting an "=" in the code.
I've
| >researched it but can seem to see what I'm missing. I only want an OK
button
| >on it and then to return focus to to the control to which the code is
| >attached. Here's the code:
| >Private Sub lbDamagedParts_Enter()
| >Me!Label23.Visible = True
| >Msgbox("For the following sections: (Chr(13))Damaged Parts, Unrelated
Prior
| >and Supp Items (Chr(13)) Select all that apply by holding as you click
to
| >select or unselect multiple entries",vbokonly,"Warning")
| >End Sub
| >Thanks so much!!
| >Pamela
|
| There are two ways to use MsgBox. One is as a statement which does not
return
| a value:
|
| MsgBox "Message", <optional operands>
|
| The other is a function, which does:
|
| iAns = MsgBox("Message", <optional operands>)
|
| Since in this case you don't want the user to reply with Yes or No, try
using
| the statement syntax. I'm also correcting the use of Chr(13) - carriage
return
| - to Chr(13) & Chr(10) - carriage-return-line-feed, and some quote
errors:
|
| Msgbox "For the following sections:" & Chr(13) & Chr(10) & _
| "Damaged Parts, Unrelated Prior and Supp Items" & Chr(13) & Chr(10) & _
| "Select all that apply by holding as you click to select " & _
| "or unselect multiple entries",vbokonly,"Warning"
|
|
| --
|
| John W. Vinson [MVP]
 
Hi Pamela,

Try this form for a message box only. I used vbCrLf in place of Chr(13):

Sub lbDamagedParts_Enter()
On Error GoTo ProcError

Me!Label23.Visible = True
MsgBox "For the following sections: " & vbCrLf _
& "Damaged Parts, Unrelated Prior and Supp Items" & vbCrLf & vbCrLf _
& "Select all that apply by holding as you click to " _
& "select or unselect multiple entries.", vbOKOnly, "Warning"

' Use this form if you need to return a result from the MsgBox function
' However, this is only appropriate if you have more than one choice, for
example
' a Yes and a No button. Notice how the parentheses are included for the
function:

'Dim intResult As Integer
'intResult = MsgBox("For the following sections: " & vbCrLf _
' & "Damaged Parts, Unrelated Prior and Supp Items" & vbCrLf & vbCrLf _
' & "Select all that apply by holding as you click to " _
' & "select or unselect multiple entries.", vbOKOnly, "Warning")

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _
& "in lbDamagedParts_Enter procedure."
Resume ExitProc
End Sub


That said, it seems to me like your users could get really tired of having
to dismiss this message box every time they needed to select items in the
list box.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 
Glad to find its faster. Always looking to learn.

--
Len
______________________________________________________
remove nothing for valid email address.
| On Mon, 4 Jan 2010 15:48:14 +1000, ".Len B"
<[email protected]>
| wrote:
|
| >Hi John,
| >Any reason you used Chr(13) & Chr(10) rather than vbCrLf?
|
| Habit... you're right, the defined constant is clearer and faster!
| --
|
| John W. Vinson [MVP]
 
Back
Top