How to print out a message saved in variable

D

Daniel

Hi

I been trying to print out a msgbox of what is saved in a
variable of type variant.
The way I would like this to work is the following:
Save messages in a table.
When ever I need to bring one out I open the table where
the messages are saved at. I get the message and I save it
into the variant variable. So then I just go MsgBox [Name
Of Variant]. This works, but it all comes out in one
whole line. I tried saving the message as follows:

"This is an example" & vbnewline & "This is the second
line"

I saved this message in the table as is, with the ", &,
and vbnewline.
So then in the program it reads the message and saves it
into the variable. But when i print out the variable, it
print out the whole thing as if it were a string. It
prints the ", &, and vbnewline.

Is there any way I can fix this?

Thank you
 
D

Dirk Goldgar

Daniel said:
Hi

I been trying to print out a msgbox of what is saved in a
variable of type variant.
The way I would like this to work is the following:
Save messages in a table.
When ever I need to bring one out I open the table where
the messages are saved at. I get the message and I save it
into the variant variable. So then I just go MsgBox [Name
Of Variant]. This works, but it all comes out in one
whole line. I tried saving the message as follows:

"This is an example" & vbnewline & "This is the second
line"

I saved this message in the table as is, with the ", &,
and vbnewline.
So then in the program it reads the message and saves it
into the variable. But when i print out the variable, it
print out the whole thing as if it were a string. It
prints the ", &, and vbnewline.

Is there any way I can fix this?

Thank you

Two ways:

1. Don't save the message expression in the table, save the result of
the expression: a character string with the embedded newline character.

or

2. Save the message expression but use "Chr(13)" instead of "vbNewLine".
Then display the mesage box by writing

MsgBox Eval([Name Of Variant])

I prefer the first way.
 
D

Daniel

Can you show me an example on how to do this?

1. Don't save the message expression in the table, save
the result of
the expression: a character string with the embedded
newline character.

-----Original Message-----
Hi

I been trying to print out a msgbox of what is saved in a
variable of type variant.
The way I would like this to work is the following:
Save messages in a table.
When ever I need to bring one out I open the table where
the messages are saved at. I get the message and I save it
into the variant variable. So then I just go MsgBox [Name
Of Variant]. This works, but it all comes out in one
whole line. I tried saving the message as follows:

"This is an example" & vbnewline & "This is the second
line"

I saved this message in the table as is, with the ", &,
and vbnewline.
So then in the program it reads the message and saves it
into the variable. But when i print out the variable, it
print out the whole thing as if it were a string. It
prints the ", &, and vbnewline.

Is there any way I can fix this?

Thank you

Two ways:

1. Don't save the message expression in the table, save the result of
the expression: a character string with the embedded newline character.

or

2. Save the message expression but use "Chr(13)" instead of "vbNewLine".
Then display the mesage box by writing

MsgBox Eval([Name Of Variant])

I prefer the first way.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
D

Dirk Goldgar

Daniel said:
Can you show me an example on how to do this?

1. Don't save the message expression in the table, save
the result of
the expression: a character string with the embedded
newline character.

It would depend on how you are inserting the messages in the table. If
you are entering them via a form or datasheet, just type the first line
of the message in the control, then press Ctrl+Enter to insert a
new-line sequence, and then type the next line. If you're inserting
them in code via a recordset, you might do something like this:

Dim rs As DAO.Recordset
Dim strMessage As String

Set rs = CurrentDb.OpenRecordset("Messages")

With rs

strMessage = _
"First line of message 1" & vbNewLine & _
"Second line of message 1"

' Add message 1.
strMessage = _
"First line of message 1" & vbNewLine & _
"Second line of message 1"

.AddNew
!MessageID = 1
!MessageText = strMessage
.Update

' Add message 2.
strMessage = _
"First line of message 2" & vbNewLine & _
"Second line of message 2"

.AddNew
!MessageID = 2
!MessageText = strMessage
.Update

.Close
End With

Set rs = Nothing

Or you could execute a SQL INSERT statement to insert the message.
 

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