RunTime error 2471 with DLOOKUP

Do I understand you correctly: This text "Text, Text, Text" " & vbNewLine & vbNewLine & "Text" can be read exactly like this in the text field of the table?
Then it is also displayed in exactly the same way in the message text. vbNewLine is then just a text.
Why is it stored like this? The text to be output would be easier to use.

But let's take a look at the current situation purely in VBA:
Code:
Private Sub Test()

    Dim NewMsgBoxTxt As String
   
    NewMsgBoxTxt = """Text, Text, Text"" "" & vbNewLine & vbNewLine & ""Text"""
    Debug.Print NewMsgBoxTxt
    MsgBox NewMsgBoxTxt
   
' fix to correct vba code inside string:
    NewMsgBoxTxt = """Text, Text, Text"" & vbNewLine & vbNewLine & ""Text"""
    Debug.Print NewMsgBoxTxt
    MsgBox NewMsgBoxTxt
    MsgBox Eval(Replace(NewMsgBoxTxt, "vbNewLine", "chr(13) & chr(10)"))

End Sub
As stated before in the thread I have several translation stored in a table. One on the many translation is to be displayed through msgbox. I have some text with linebreaks for clarity. Something of the sort :
Text, text, text​
Text​
So, in my table I have written the string I thought I could pass as variable in the form "Text, Text, Text" " & vbNewLine & vbNewLine & "Text"
If this works using declared variables in VBA as in
Code:
NewMsgBoxTxt = "Text, Text, Text" " & vbNewLine & vbNewLine & "Text"
MsgBox NewMsgBoxTxt

it doesn't when the string is fetched from the table using dlookup and shows only "Text, Text, Text" " & vbNewLine & vbNewLine & "Text"
 
Why not just have those fields as long text and actually put the CRLF in the field?

Or, if you have to stick with what you are trying....

Code:
tt= dlookup("description","twgonder","ID=2")
? tt
test , text , tert  vbnewline  vbnewline  test
msgbox tt
msgbox replace(tt,"vbnewline",vbcrlf)
1742982928414.png
 
Last edited:
@Doc - your link is not about vba

Attributes
ObsoleteAttribute

Applies to​

Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
10.0
[th]
Product​
[/th][th]
Versions​
[/th]​
[th]
.NET​
[/th]​
[th]
.NET Framework​
[/th]​
[th]
UWP​
[/th]​

See also​

 
David, the second part of my post was right, though. I've never had issues when using vbCrLf.
 

Users who are viewing this thread

Back
Top Bottom