Solved Fetching String Value from Table and Displaying in Message Box with CrLf (1 Viewer)

Pac-Man

Active member
Local time
Today, 14:24
Joined
Apr 14, 2020
Messages
416
Hello,

This might look like little strange question but I want to display a message in msgbox with vbCrLf after retrieving the message from a table. See the code below:

Markdown (GitHub flavored):
Function test()

    Dim UpdateMsg As String
    Dim UpdateMsg1 As String

'    UpdateMsg = DLookup("UpdateMsg", "tblSettingsServer", "VersionID = 1")
'    UpdateMsg1 = "New version is released. Changes Includes:" & vbCrLf & "-Enhanced Security" & vbCrLf & "-Ability to add new employee"

    MsgBox UpdateMsg, vbInformation, "Update Notification"

End Function

In my tblSettingsServer, UpdateMsg field has the following text in it:
New version is released. Changes Includes:" & vbCrLf & "-Enhanced Security" & vbCrLf & "-Ability to add new employee

Note that there is no quotation mark in start and end of the value as MSA will add itself as UpdateMsg is a string variable. If we put those quotation marks in start and end of message, it makes UpdateMsg1. But problem is, UpdateMsg1 gives desired results while UpdateMsg (that is fetched by either DLookup or using recordset method) doesn't. See the attached screenshots of both the results.

Do I have to perform some other operation on UpdateMsg after fetching it from the table?

Best Regards,
Abdullah
 

Attachments

  • UpdateMsg.PNG
    UpdateMsg.PNG
    4.9 KB · Views: 113
  • UpdateMsg1.PNG
    UpdateMsg1.PNG
    4.2 KB · Views: 102
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 02:24
Joined
Oct 29, 2018
Messages
21,480
Hi. Don't use code in your table. Instead store the actual characters. In this case, the character(s) for a carriage return.
 

isladogs

MVP / VIP
Local time
Today, 10:24
Joined
Jan 14, 2017
Messages
18,242
Another approach would be to create a small popup form to display your message.
One advantage of this would be that you could use a rich text memo field allowing e.g. bold formatting for part of the text
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:24
Joined
May 7, 2009
Messages
19,248
try this one:
put in UpdateMsg field (on VersionID=1,without quote):

New version is released. Changes Includes:<p>-Enhanced Security<p>-Ability to add new employee

Code:
Function test()

    Dim UpdateMsg As String
    'Dim UpdateMsg1 As String

    UpdateMsg = Replace(DLookup("UpdateMsg", "tblSettingsServer", "VersionID = 1"), "<p>", vbCrLf)
'    UpdateMsg1 = "New version is released. Changes Includes:" & vbCrLf & "-Enhanced Security" & vbCrLf & "-Ability to add new employee"

    MsgBox UpdateMsg, vbInformation, "Update Notification"

End Function
 

Pac-Man

Active member
Local time
Today, 14:24
Joined
Apr 14, 2020
Messages
416
Hi. Don't use code in your table. Instead store the actual characters. In this case, the character(s) for a carriage return.
I used Chr(13) in the table but it is shown exactly (i.e. chr(13)) in the message box.
 

Pac-Man

Active member
Local time
Today, 14:24
Joined
Apr 14, 2020
Messages
416
try this one:
put in UpdateMsg field (on VersionID=1,without quote):

New version is released. Changes Includes:<p>-Enhanced Security<p>-Ability to add new employee

Code:
Function test()

    Dim UpdateMsg As String
    'Dim UpdateMsg1 As String

    UpdateMsg = Replace(DLookup("UpdateMsg", "tblSettingsServer", "VersionID = 1"), "<p>", vbCrLf)
'    UpdateMsg1 = "New version is released. Changes Includes:" & vbCrLf & "-Enhanced Security" & vbCrLf & "-Ability to add new employee"

    MsgBox UpdateMsg, vbInformation, "Update Notification"

End Function
Thanks a lot. It works. Thank you very much @arnelgp
 

Pac-Man

Active member
Local time
Today, 14:24
Joined
Apr 14, 2020
Messages
416
Another approach would be to create a small popup form to display your message.
One advantage of this would be that you could use a rich text memo field allowing e.g. bold formatting for part of the text
Thanks for suggestion. I like what you suggested. I could make formatted message box in my own form. Even in that case I think I have to use methods suggested by @arnelgp or @theDBguy (if I could make that character method work) to go to new line in the form. But thanks for new idea for having custom designed form for update notification.
 

isladogs

MVP / VIP
Local time
Today, 10:24
Joined
Jan 14, 2017
Messages
18,242
Not necessarily.
Use a form with a rich textbox to enter the message text. Any line returns and formatting can be done as you type the message text
See the Customised Message Forms in my Attention Seek example app
 

Pac-Man

Active member
Local time
Today, 14:24
Joined
Apr 14, 2020
Messages
416
Not necessarily.
Use a form with a rich textbox to enter the message text. Any line returns and formatting can be done as you type the message text
See the Customised Message Forms in my Attention Seek example app
The issue is, I don't your the text in the text box. I tried the message in UpdateMsg field in my table and then fetch it using DLookup. Purpose is so that I can change my message to inform the users about changelog of new update using there old FE (which fetch the message from a table in backend).
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:24
Joined
Oct 29, 2018
Messages
21,480
I used Chr(13) in the table but it is shown exactly (i.e. chr(13)) in the message box.
Of course. Because you didn't use the actual character. I mean, to represent a space, you wouldn't enter Chr(20), right? So, the same goes for a carriage return. To enter it as a character in the table, try holding down the Ctrl key and then hit the Enter key. Cheers!
 
Last edited:

Pac-Man

Active member
Local time
Today, 14:24
Joined
Apr 14, 2020
Messages
416
To enter it as a character in the table, try holding down the Ctrl key and then hit the Enter key. Cheers!
I didn't know about Ctrl + Enter. I tried hitting enter and by doing that it moves to next field/row so I thought you might be referring to chr(13), I found over Google that this chr represent crlf. Thanks a lot.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:24
Joined
Oct 29, 2018
Messages
21,480
I didn't know about Ctrl + Enter. I tried hitting enter and by doing that it moves to next field/row so I thought you might be referring to chr(13), I found over Google that this chr represent crlf. Thanks a lot.
Hi. You're welcome. Good luck with your project.
 

isladogs

MVP / VIP
Local time
Today, 10:24
Joined
Jan 14, 2017
Messages
18,242
The issue is, I don't your the text in the text box. I tried the message in UpdateMsg field in my table and then fetch it using DLookup. Purpose is so that I can change my message to inform the users about changelog of new update using there old FE (which fetch the message from a table in backend).

My explanation was intended to fulfil that exact purpose. I use something very similar in my own commercial apps.

WhatsNew.gif

@theDBguy has explained exactly what I was referring to when creating your rich text memo field with info about the latest update.
 

Pac-Man

Active member
Local time
Today, 14:24
Joined
Apr 14, 2020
Messages
416
My explanation was intended to fulfil that exact purpose. I use something very similar in my own commercial apps.

View attachment 82748
@theDBguy has explained exactly what I was referring to when creating your rich text memo field with info about the latest update.
That is great. I'll try that. How did you make few letters between the paragraph bold. When i try to do that, it makes the complete text box bold, I whichever formatting I do, is applied to the whole field. How can it be done in few words in a field?
 

isladogs

MVP / VIP
Local time
Today, 10:24
Joined
Jan 14, 2017
Messages
18,242
As already stated, by using a rich text memo field.
This is fully explained in my Attention Seek example app (see link in post #8)
1591944498162.png
 

Pac-Man

Active member
Local time
Today, 14:24
Joined
Apr 14, 2020
Messages
416
As already stated, by using a rich text memo field.
This is fully explained in my Attention Seek example app (see link in post #8)
View attachment 82754
Thanks a lot. I had seen attention seeker demo db couple of weeks ago (just it's working). I'll look into the code and method too. Thanks a lot for such an excellent database.
 

Users who are viewing this thread

Top Bottom