Solved

syntax for msgbox

Posted on 2004-08-17
4
360 Views
Last Modified: 2008-02-20
I cant seem to get the syntax right for this types of message boxes. An explaination of the &'s and "'s gets an A

intAns = MsgBox("You are about to delete " & strFirstName & "" & strLastName & " from the database.  Are you sure?", vbYesNo, "The Contact Manager")

returns a message box with the last name not there
0
Comment
Question by:MikeORTEC
4 Comments
 
LVL 4

Expert Comment

by:cachedVB
ID: 11827217
Change it to strFirstName & " " & strLastName with a space in there :)
0
 
LVL 12

Accepted Solution

by:
BobLamberson earned 50 total points
ID: 11827226
Hi MikeORTEC,

Your syntax is ok, if you have the variables dimmed correctly. Have you checked the obvious, that the strLastName var to be sure it has data in it?
The ampersand & is used to concantonate two strings and the " are used to delineate a literal string that is written out. When you run your function vb substitutes a string for the variable and the & joins the two strings.
Here is some test code using your syntax - open a new project and just add this code to the forms code, then step through it.
I only added a space in the string between strFirstName and strLastName.

Private Sub Form_Click()
Dim intAns As VbMsgBoxResult
Dim strFirstName As String
Dim strLastName As String
strFirstName = "Joe"
strLastName = "Wilson"
intAns = MsgBox("You are about to delete " & strFirstName & " " & strLastName & " from the database.  Are you sure?", vbYesNo, "The Contact Manager")
If intAns = vbYes Then MsgBox "User selected yes"
If intAns = vbNo Then MsgBox "User selected no"
End Sub

hope this is helpful

Bob
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 11828057
Break at that point and make sure strLastName has a correct value
0
 

Author Comment

by:MikeORTEC
ID: 11829103
Thanks Bob.  Very helpful.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question