Adding a reference field to .htmlbody

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aflores41
    New Member
    • Nov 2014
    • 57

    Adding a reference field to .htmlbody

    Hello,

    What's the best way to add a reference field to a .htmlbody of access db.
    For example:
    Code:
    "Dear Mr. &![LName]&,"
    Challenges on this code is it doesn't reference the field. It reads it as text.

    Thank you!

    -Alain
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3664

    #2
    Alain,

    I can't specifically address the HTML aspect of this, as I have not had success with using HTML in VBA for sending e-mails.

    However, concerning the code you posted, this will work better:
    Code:
    "Dear Mr. " & ![LName] & ","
    It is important to get all the quotation marks in the right places.

    Comment

    • aflores41
      New Member
      • Nov 2014
      • 57

      #3
      Once again, thank you!

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3664

        #4
        Glad I can be of service!

        Comment

        • aflores41
          New Member
          • Nov 2014
          • 57

          #5
          Another issue, I'm trying to do page breaks. Was using
          Code:
          "Dear Mr. " & ![LName] & "," & <br/> &
          or
          Code:
          <br> </br>
          or
          Code:
          & vbCrLf &
          but that doesn't work. Also, adding formatting such as bolding the font. Thanks so much!

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3664

            #6
            I have been playing with HTML just this morning!

            Since E-Mail does not have a "page", that type of break won't really work here--it just adds another line. To Bold some text, add the following (assuming you have a String called strBody):

            strBody = "This is <B>Bold</B> Text. This is <I>Italic</I>."

            A quick list of some HTML tags can be found here:

            HTML Tags

            Hope this hepps.

            Comment

            • twinnyfo
              Recognized Expert Moderator Specialist
              • Nov 2011
              • 3664

              #7
              P.S. Don't forget to declare the BodyFormat as HTML and use the .HTMLBody Property when sending.

              Comment

              • aflores41
                New Member
                • Nov 2014
                • 57

                #8
                Thanks! Well I got everything to work except for bolding the referenced field.

                Code:
                "Dear Mr. " & <b>![LName]</b> & ","
                error is with
                Code:
                <b>![LName]</b>
                as syntax error.

                Comment

                • twinnyfo
                  Recognized Expert Moderator Specialist
                  • Nov 2011
                  • 3664

                  #9
                  Try this:

                  Code:
                  "Dear Mr. <B>" & ![LName] & "</B>,"

                  Comment

                  • aflores41
                    New Member
                    • Nov 2014
                    • 57

                    #10
                    Also, if anyone knows how to add the default signature from outlook to the
                    Code:
                    .htmlbody = strbody
                    . code.

                    Comment

                    • aflores41
                      New Member
                      • Nov 2014
                      • 57

                      #11
                      Code:
                      "Dear Mr. <B>" & ![LName] & "</B>,"
                      Works!
                      Thank you!

                      Comment

                      • aflores41
                        New Member
                        • Nov 2014
                        • 57

                        #12
                        Code:
                        'GET DEFAULT EMAIL SIGNATURE
                            signature = Environ("appdata") & "\Microsoft\Signatures\"
                            If Dir(signature, vbDirectory) <> vbNullString Then
                                signature = signature & Dir$(signature & "*.htm")
                            Else:
                                signature = ""
                            End If
                            signature = CreateObject("Scripting.FileSystemObject").GetFile(signature).OpenAsTextStream(1, -2).ReadAll
                        '-------------------------------------------------------------------------------------------------------------
                        Code:
                        strbody = "dear ....." & signature
                        .htmlbody = strbody
                        VBA code for adding default signature from outlook to .htmlbody in access.

                        Thanks all!

                        -Alain

                        Comment

                        • twinnyfo
                          Recognized Expert Moderator Specialist
                          • Nov 2011
                          • 3664

                          #13
                          Your first block of code may work for a standard Windows machine, although I would declare separate strings for the Path and the actual signature. Also creates problems if there are multiple Signature blocks for the same user (I have two). However, when Windows starts moving stuff around again.....

                          I've been able to get the Signature block to appear in a blank e-mail, but haven't been successful in joining my HTMLBody with the signature block.

                          All research I have done has found solutions similar to what you have: find the signature file in the file structure. But, as mentioned, there are challenges with that.

                          Still lookin'........ .....

                          Comment

                          Working...