Hello,
Following this post:
https://www.accessforums.net/program...tml#post275857
I want to send formatted email but somehow the email comes with question marks instead of text.
What's the problem?
Hello,
Following this post:
https://www.accessforums.net/program...tml#post275857
I want to send formatted email but somehow the email comes with question marks instead of text.
What's the problem?
Try using a report,
using DOCMD.SendObject
(but how are you sending yours?)
That's the way I'm sending now.
HTML text is stored in the table.
How do I use your method?Code:Dim objRecordset As Object Set objRecordset = CreateObject("adodb.recordset") Dim s As String Dim iCfg As Object Dim iMsg As Object Dim ito As String Dim strhtml As String Dim i As Integer Dim value As Variant CurrentDb.Execute "UPDATE testhtml SET STR= Replace ([STR], '{!Contact.FirstName}','" & Me.first_þþname & "')" objRecordset.ActiveConnection = CurrentProject.Connection objRecordset.Open ("testhtml") While objRecordset.EOF = False 'check for match If objRecordset.Fields.Item(0).value = 2 Then 'get value strhtml = objRecordset.Fields(1).value 'exit loop objRecordset.MoveLast End If objRecordset.MoveNext Wend Dim a As String ito = Me.E_mail_Address Set iCfg = CreateObject("CDO.Configuration") Set iMsg = CreateObject("CDO.Message") With iCfg.Fields .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "XXX" .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "XXXXX" .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "XXXXX" .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = "XXXXX" .Update End With With iMsg .Configuration = iCfg .Subject = "Subject" .To = ito .HTMLBody = strhtml .Send End With Set iMsg = Nothing Set iCfg = Nothing
I will be happy if you could explain to me.
Thank you.
Your code does not make much sense. You are emailing the value of one field from a single record within a table and the record used is selected randomly. I do not believe your screenshot is the actual result of the code you posted.
My HTML code stored in table called "testhtml" in field called "STR".
I find this record that I have in the table testhtml and email the contents of the field STR.
This is the part where I look for the record and place its contents in the variable strhtml =THIS MY HTML CODE.
Code:While objRecordset.EOF = False 'check for match If objRecordset.Fields.Item(0).value = 2 Then 'get value strhtml = objRecordset.Fields(1).value 'exit loop objRecordset.MoveLast End If objRecordset.MoveNext Wend
This is the part that sends the message:
But for some reason i get question marks.Code:ito = Me.E_mail_Address Set iCfg = CreateObject("CDO.Configuration") Set iMsg = CreateObject("CDO.Message") With iCfg.Fields .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "XXX" .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "XXXXX" .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "XXXXX" .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = "XXXXX" .Update End With With iMsg .Configuration = iCfg .Subject = "Subject" .To = ito .HTMLBody = strhtml .Send End With Set iMsg = Nothing Set iCfg = Nothing
I looked at the code and the reason I say the selected record is random is you use an UPDATE query to update a record and then your loop grabs a random record. Why use a loop to grab a single record? Why run an update query to update a table if you are emailing the value of a single field?
Maybe the value of your field is not what you expect it to be. Have you tried pasting it into a new text file and saving it as an HTML? Maybe the record that you think you are using for the email is not the actual record retrieved by the loop.
My UPDATE query in the future will include "WHERE" But right now it is irrelevant. There is only one record update.
In my record (HTML) There are fields which i need to replace them in the fields of the customer to which i sent EMAIL.
So I use the Update and Replace to replace these expressions.
I deleted this part of the code but I use a message box to view the code that I want to send is exactly what I need.
There could be a problem with encoding of the EMAIL?
You have another way to retrieve the record and put its value in a variable instead of LOOP?
I am removing my suggestions.
I try to avoid it.
I do not want to put all my HTML code in VBA my code is very long.
And so I want to store it somewhere else and just replace several fields before sending.
I am removing my suggestions.
have you checked the value of [STR] before and after the replace? because once you've run it, the bit you want to replace is no longer there - assuming the replace worked.
have you tried assigning STR to strhtml and then run the replace on strhtml i.e.
.HTMLBody = replace(strhtml,'{!Contact.FirstName}', Me.first_þþname)
Also, what is the field STR datatype? is it a memo field? if so is it set to plain text? suggest try it both ways. Richtext has a limited range of formatting compared with full on html so perhaps the code is not being saved correctly after your update.
You are only replacing one value (contact name), you still have others e.g. createddate which you are not populating - is it possible these are messing with your code? suggest remove them for now until you solve the first issue.
I am removing my suggestions.
First of all, thank you very much !!! I just realized the problem of the updateding the table.have you checked the value of [STR] before and after the replace? because once you've run it, the bit you want to replace is no longer there - assuming the replace worked.
have you tried assigning STR to strhtml and then run the replace on strhtml i.e.
.HTMLBody = replace(strhtml,'{!Contact.FirstName}', Me.first_þþname)
Also, what is the field STR datatype? is it a memo field? if so is it set to plain text? suggest try it both ways. Richtext has a limited range of formatting compared with full on html so perhaps the code is not being saved correctly after your update.
You are only replacing one value (contact name), you still have others e.g. createddate which you are not populating - is it possible these are messing with your code? suggest remove them for now until you solve the first issue.
So I used your method which is much more suitable and correct!
The field type is long text\plain text. I keep getting question marks in the content of the email. Maybe the problem related to that i am using a non-Latin characters?
Does anyone have any idea how to solve the issue of question marks?
you never answered this
have you checked the value of [STR] before and after the replace?