We help IT Professionals succeed at work.

I need help passing vbLF in a string to a textbox control in ACCESS 2010.

Hi Experts,
I have the following VBA code where I use vbLF in a string in my ACCESS application.  When I pass the string with the vbLF to my textbox control, the data is put in a single line.  There is no carriage return or line feed that occurs. How can I fix this?

See my code below
Private Sub viewEmail(strValues As String)
On Error GoTo ErrorHandler
         Dim rs2 As DAO.Recordset
         Dim db2 As Database
         Dim strSQL2 As String
         Dim strPassedValue As String
         Dim intJobId As Integer
         Dim strTech As String
         Dim varVals As Variant
         Dim strEmailMessage As String
         strPassedValue = strValues 'Me.OpenArgs
         varVals = Split(strPassedValue, "/")
         intJobId = CInt(Trim(varVals(0)))
         strTech = Trim(varVals(1))
         Set db2 = CurrentDb
         strSQL2 = "SELECT * FROM Schedule_Table WHERE JobID = " & intJobId & " AND Tech_Name = '" & strTech & "'"
         Set rs2 = db2.OpenRecordset(strSQL2)
          If rs2.RecordCount > 0 Then
            strEmailMessage = rs2![JobName] & vbLf
            strEmailMessage = strEmailMessage & rs2![VenueName] & vbLf
            strEmailMessage = strEmailMessage & rs2![AreaName] & vbLf
            MsgBox ("There was an issue generating the email text.")
          End If
        Me.txtEmailBody.Value = strEmailMessage

'    Set rsScheduled = Nothing
    Exit Sub
    MsgBox "Error No: " & Err.Number _
       & " in " & Me.ActiveControl.name & " procedure; " _
       & "Description: " & Err.Description
    Resume ExitSub
End Sub

Open in new window

thanks in advance,
Watch Question

A textbox won't allow CR's from the helpfile:
Up to 63,999 characters. (If the Memo field is manipulated through DAO and only text and numbers [not binary data] will be stored in it, then the size of the Memo field is limited by the size of the database.)
So to show this use a rich text control from the Active X controls.
Most Valuable Expert 2015
Distinguished Expert 2018
You have to use vbCrLf or vbNewLine, not vbLf.

Database Architect / Application Developer
Top Expert 2007
Or you can use:
strEmailMessage = rs2![JobName] & Chr(13) & Chr(10)

"A textbox won't allow CR's from the helpfile:"
Sorry, but that's not true.  You can most definitely enter a LFCR in a Text Box.
And on the Property Sheet of a Text Box, you can set Enter Key Behavior to "New Line in Field"