msgbox truncating the message

G

GeorgeMar

Never had this problem before, but there is always a first time.

Here it goes! I am a creating a string variable strMsg that contains the
message. The variable is populated from a Do loop. eg. strMsg=strMsg & "...
some text ..." & chr(13) & chr(10).

The problem is, let's say, I have four lines in the message, only the first
two will display when I use Msgbox strMsg. When I view the contents in
DebugPrint strMsg, I see all four lines.

Anybody come across this. I have even tried decompiling, to no avail.

many thanks
george
 
D

Douglas J. Steele

How long is the message? The following works fine for me (all nine lines
show in the message box):

Sub ShowMessageBox()
Dim strOutput As String

strOutput = "Line1" & vbCrLf & _
"Line2" & vbCrLf & _
"Line3" & vbCrLf & _
"Line4" & vbCrLf & _
"Line5" & vbCrLf & _
"Line6" & vbCrLf & _
"Line7" & vbCrLf & _
"Line8" & vbCrLf & _
"Line9"

MsgBox strOutput

End Sub

and I know I've gone far higher than that in production. There is a limit to
how long the string can be (but unfortunately I don't remember it)
 
K

Ken Snell \(MVP\)

From ACCESS Help file:

"The maximum length of prompt is approximately 1024 characters, depending on
the width of the characters used."
 
G

GeorgeMar

Thank you both!

The message I am showing is approx 200 chars long on four lines. I have
tried reducing each line to a minimum, 'twas to no avail. It seems hell bent
on only showing the first two lines. The intriguing thing is that I can see
the whole message in Debug.Print.

Thanks
George
 
R

Robert Morley

Have you checked that you're not including unprintable characters anywhere
in it? Perhaps it's something that's confusing the message box, but the
debug window is just ignoring it. Worst case scenario, post the code that
creates the message, then we can all try it and maybe narrow it down.


Rob
 
G

GeorgeMar

Rob

You are right on the mark. Just figured it out now.

I am using Dev Ashish's code for "Retrieving remote user name". Although it
has a Trim function, it wasn't removing the trailing unprintable characters.

I added: Left(strUser,Instr(1,strUser,chr(0)-1) and it worked.

Thank you all for your help.

regards
george
 
G

GeorgeMar

For those following this thread.

The culprit is the Computer name and not the User name.

George
 

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