Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    alex1888 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    10

    E-mail messages are sent with question marks

    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.
    Click image for larger version. 

Name:	exmp1.PNG 
Views:	27 
Size:	30.2 KB 
ID:	20906


    What's the problem?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Try using a report,
    using DOCMD.SendObject

    (but how are you sending yours?)

  3. #3
    alex1888 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    10
    That's the way I'm sending now.


    HTML text is stored in the table.

    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
    How do I use your method?


    I will be happy if you could explain to me.


    Thank you.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    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.

  5. #5
    alex1888 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    10


    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:

    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
    But for some reason i get question marks.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    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.

  7. #7
    alex1888 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    10
    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.

    Click image for larger version. 

Name:	exp.png 
Views:	26 
Size:	55.5 KB 
ID:	20909



    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?

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I am removing my suggestions.

  9. #9
    alex1888 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    10
    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.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I am removing my suggestions.

  11. #11
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,831
    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.

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I am removing my suggestions.

  13. #13
    alex1888 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    10
    Quote Originally Posted by Ajax View Post
    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.
    First of all, thank you very much !!! I just realized the problem of the updateding the table.

    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?

  14. #14
    alex188 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    6
    Does anyone have any idea how to solve the issue of question marks?

  15. #15
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,831
    you never answered this

    have you checked the value of [STR] before and after the replace?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Ho to obtain TOP 5 marks
    By Som in forum Reports
    Replies: 21
    Last Post: 01-22-2015, 11:41 AM
  2. Replies: 2
    Last Post: 12-13-2013, 03:13 PM
  3. InStr() and quotation marks
    By Puebles in forum Programming
    Replies: 3
    Last Post: 11-22-2013, 07:36 AM
  4. Replies: 1
    Last Post: 09-14-2012, 10:27 AM
  5. Custom messages to Access' default error messages.
    By evander in forum Programming
    Replies: 1
    Last Post: 06-26-2010, 02:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums