Solved

syntax for msgbox

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now