Problem filling a textbox (format RichText) with Richtext

Bobcat42

New member
Local time
Today, 21:49
Joined
Feb 20, 2025
Messages
2
Hello,

I have an Emailform with a Richtext formatted textbox for the body of the Email. Now I want to fill the textbox for the body with some predefined text template that is also formatted as richtext in the form load or open event. If I do that the predefined text looses it's linebreaks in the textbox. If I output the same text in the immidiate window it still has the linebreaks in it.

This is basically what I do in the form load event:
---------------
Private Sub Form_Load()

Dim strMailtext As String
'check if a template was chosen
If Not IsBlankEMB(Me.OpenArgs) Then
Call modCDO.Mailtext(Me.OpenArgs, strMailtext)
Me.txtText = strMailtext
End If
'output in the immidiate window for validation
Debug.Print Me.txtText
End Sub
---------------
and this is part of the function that gets the correct mailtext:
---------------
Public Function Mailtext(ByVal MeldungID As Integer, ByRef strMailtext As String)
10 On Error GoTo Err_Handler

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rstText As DAO.Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM qry_Meldung WHERE TUD_ID = " & MeldungID, dbOpenDynaset, dbSeeChanges)
If rst.EOF Or rst.BOF Then Exit Function
Set rstText = db.OpenRecordset("SELECT * FROM dbo_tbl_Data_Mailtexte_check where MEL_ID = " & rst!Meldebestaetigung, dbOpenDynaset, dbSeeChanges)
strMailtext = rstText!Block1
strMailtext = Replace(strMailtext, "[Vorname]", rst!Vorname)
strMailtext = Replace(strMailtext, "[Nachname]", rst!Nachname)
strMailtext = Replace(strMailtext, "[Meldedatum]", rst!Meldedatum)

rst.Close
rstText.Close
db.Close
Set rst = Nothing
Set rstText = Nothing
Set db = Nothing

Exit_Handler:
2000 Exit Function

Err_Handler:
2100 clsErrorHandler.HandleError "modCDO", "Mailtext", True
2200 Resume Exit_Handler
End Function
---------------
Both basically work as they should. I can enter linebreaks after the text was imported into the textbox of the Email form and send the email then, but the template is basically meant to help the user to have less work.

Does anybody have a clue why the textbox looses the linebreaks? I could of course add richbox breaks (<br>, <div>, ....) to the template, but since everything is richtext I was hoping to prevent that.

PS: The Mailform is an unbound form.

Thank you for your help in advance.
 
Have a look at the code in the HTML email example in my CDO Email Tester app.

 
I could of course add richbox breaks (<br>, <div>, ....) to the template, but since everything is richtext I was hoping to prevent that.
You didn't show us your template, but I don't understand the above statement. There is no avoiding using <br> and such since that is what rich text uses. So, if your template is not using those, I think you'll have to start using them.
 

Users who are viewing this thread

Back
Top Bottom