Solved

syntax for msgbox

Posted on 2004-08-17
4
364 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:
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

749 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