Solved

syntax for msgbox

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 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