Msgbox

T

TimT

Can anyone tell me what I'm doing wrong?
I get a compile error and "type-declaration character does not match
declared data type" then it highlights the first &vbNewLine in the second
line:

MsgBox "You are about to roll forward the" & vbNewLine& _
& "Cumulative Beginning Balance for this company!" & vbNewLine& & vbNewLine&
& "You will be replacing current cumulative numbers with end of year
amounts." & vbNewLine& _
& "ARE YOU SURE YOU WISH TO PROCEED?", VbMsgBoxStyle = vbOKCancel, "WAIT A
SECOND!!"
'to verify cumulative rollover

Thanks for any help!
 
D

Dennis

I thinks its beacuse you have double ampersands throughout. You only need a
single ampersand to concatenate and you do not need one to start a new line
after the underscore.
 
T

TimT

Thanks Dennis. You thinks correctly!
Big help!

Dennis said:
I thinks its beacuse you have double ampersands throughout. You only need a
single ampersand to concatenate and you do not need one to start a new line
after the underscore.
 
D

Douglas J. Steele

Actually, the fact that he doesn't have a space between vbNewLine and the
ampersand implies that he's trying to cast vbNewLine as a long integer (it's
a throw-back notation, where Dim x& declares x to be a Long, Dim x% declares
it to be an Integer, Dim x$ declares it to be a String and so on)

The problem is, vbNewLine isn't a Long Integer: it's a string:

?TypeName(vbNewLine)
String

You're correct that removing the ampersands will solve the problem:

MsgBox "You are about to roll forward the" & vbNewLine _
& "Cumulative Beginning Balance for this company!" _
& vbNewLine & vbNewLine _
& "You will be replacing current cumulative numbers with end of year " _
& " amounts." & vbNewLine _
& "ARE YOU SURE YOU WISH TO PROCEED?", _
VbMsgBoxStyle = vbOKCancel, "WAIT A SECOND!!"

Using $ to declare them as strings should work too (but it's completely
unnecessary):

MsgBox "You are about to roll forward the" & vbNewLine$ _
& "Cumulative Beginning Balance for this company!" _
& vbNewLine$ & vbNewLine$ _
& "You will be replacing current cumulative numbers with end of year " _
& " amounts." & vbNewLine$ _
& "ARE YOU SURE YOU WISH TO PROCEED?", _
VbMsgBoxStyle = vbOKCancel, "WAIT A SECOND!!"
 
T

TimT

Hey Dennis I have another question,
How do you make the sub stop when cancel is clicked on the messagebox?
I thought it did that automatically.
 
V

Van T. Dinh

In addition:

1. Get rid of the String "VbMsgBoxStyle =". I am fairly sure the error
comes from this.

2. I would normally use vbCrLf rather than vbNewLine in this case.
 
T

TimT

Van,
Thanks 1 and 2 cleared the problem!
I realized vbMsgBoxStyle = was wrong right after I sent the message before!
 
D

Dirk Goldgar

Van T. Dinh said:
2. I would normally use vbCrLf rather than vbNewLine in this case.

But vbNewLine is identical to vbCrLf in all versions of Access.
vbNewLine is just more "abstracted" from the implementation details.

Actually, vbCr works just as well, in a MsgBox.
 
K

Kevin K. Sullivan

Tim,

Pardon me for jumping in. To respond to the button that was pressed,
you need to put the MsgBox function in an If block or Select Case:

---------air code-------------------

'I put the message text in a separate variable for code readability
Dim strMsg as String

strMsg = "You are about to roll forward the" & vbNewLine _
& "Cumulative Beginning Balance for this company!" _
& vbNewLine & vbNewLine _
& "You will be replacing current cumulative numbers with end of year " _
& " amounts." & vbNewLine _
& "ARE YOU SURE YOU WISH TO PROCEED?"


Select Case MsgBox(strMsg, vbOKCancel, "WAIT A SECOND!!")

Case vbCancel:
Exit Sub
Case vbOK:
'OK response code goes here
End Select
 
V

Van T. Dinh

Thanks Dirk.

I always thought vbCrLf means Return + Line Feed but a quick test confirm
what you wrote.
 
D

Dirk Goldgar

Van T. Dinh said:
Thanks Dirk.

I always thought vbCrLf means Return + Line Feed but a quick test
confirm what you wrote.

Oh, it does mean that. But vbNewLine, on a Windows platform, is also
Return+Line Feed, as this is the control-code sequence that means "new
line" on this platform. If you look in the help file for Access 97
under "Miscellaneous Constants", it says

<quote>
vbNewLine Chr(13) + Chr(10) or Chr(13) Platform-specific new
line character; whichever is appropriate for current platform
</quote>

IIRC, back when they thought there would be an Access for Macintosh, the
idea was that vbNewLine would be equivalent to vbCr on that platform.
And if there were an Access for Unix, I think it would be the same as
vbCr there, too.

As for the MsgBox function, it must have logic in it to accept either
CR+LF or CR alone as a line separator.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top