Solved

syntax for msgbox

Posted on 2004-08-17
4
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:
Bob Lamberson 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

696 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