Results 1 to 12 of 12
  1. #1
    Join Date
    Sep 2010
    Posts
    5

    Unhappy Unanswered: sendobject problem

    Below is a sample of my code which is used to populate a message that must be e-mailed. When outlook comes up, it is seen in the proper format and shows the carriage returns as was formatted by my code. When the message is sent, I lose the carriage returns.

    Can anyone help me with this one? Why is outlook defaulting to plain text when I use the sendobject command?

    c1 = " The following purchase requisition requires additional approval due to the following reason: "
    c1b = " [indicate with an X all that apply]"
    c2 = " [ ] Air Conditioners (DC and Facilities)"
    c3 = " [ ] Clothing And Jackets(FDC)"
    c4 = " [ ] Food Purchases (DC)"
    c5 = " [ ] Furniture(DC And Facilities)"
    ...
    Msg = Chr(13) & c1 & Chr(13) & c1b & Chr(13) & Chr(13) & c2 & Chr(13) & c3 & Chr(13) & c4 & Chr(13) & c5 & Chr(13)

    m1 = " I, John Doe, approve this requisition on " & Date "
    m2 = " Requisition: " & Left([fy], 3) & Me![dhs #]
    m3 = " Description: " & Me![DESCRIPTION]
    m4 = " Budget Code: " & Me![BCODE]
    m5 = " Object Code: " & Me![OCODE]
    m6 = " Total Cost: " & Me![Req Amt]
    m7 = " Requester: " & Me![CONTACT]
    m8 = " Suggested Vendor: " & Me![CONTRACTOR]

    Msg = Msg & Chr(13) & m1 & Chr(13) & Chr(13) & m2 & Chr(13) & m3 & Chr(13) & m4 & Chr(13) & m5 & Chr(13) & m6 & Chr(13) & m7 & Chr(13) & m8

    DoCmd.SendObject acSendNoObject, , acFormatHTML, "jpadilla@dot.nyc.gov", "jpadilla@dot.nyc.gov", , "Approval for requisition " & Left([fy], 3) & [dhs #], Msg2, -1, "E:\fiscal programs\req\ReqApproval1.htm"

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try replacing Chr(13) by vbNewLine which is Chr(13) & Chr(10) (or CrLf).
    Have a nice day!

  3. #3
    Join Date
    Sep 2010
    Posts
    5

    Unhappy sendobject problem

    I tried doing what you suggested but it did not work. It looks like the problem lies with outlook, it keeps reverting back to "plain text".

    In the sendobject there is an html template option which I am trying to apply. Would this control how outlook would send the e-mail?

  4. #4
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    I'm not sure about the DOT in NYC, but many govt networks have banned the use of HTML formatted email, and require all messages to be composed and displayed in plain text.

  5. #5
    Join Date
    Sep 2010
    Posts
    5
    This is probably true, but all I know is I have the option to change my outlook output from plain text to html. This has not been restricted by my agency's network administrators. When I do this change, it holds the proper formatting of the text. That is all I am trying to do. There are no hyperlinks in the message or pictures in the message.

  6. #6
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    I assembled a macro with the sendobject command, and then had the system convert it to VB. Here's what it gave me:
    Code:
    DoCmd.SendObject acFunction, "", "HTML(*.html)", "a@a.com", "", "", "Test", "This is only a test", True, ""
    Try swapping the "HTML(*.html)" bit for the acFormatHTML in your string. this is using access 2007, by the way.

  7. #7
    Join Date
    Sep 2010
    Posts
    5
    I am using Access 2003. Your suggestion did not work for some odd reason. It returned the following error message:

    Run Time Error 2487:

    The object type argument for the action or method is blank or invalid.

    I am not sure if Access 2003 recognizes the acFunction clause. It did not come up when I searched for it in the help files.

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    The constant acFunction does exist in Access 2003. It is a member of the AcObjectType class and its value is 10 (decimal). You're receiving this error because the next parameter is empty:
    Code:
    DoCmd.SendObject acFunction, "",...
    The Access help system (type SendObject in the search window) explains that the SendObject method is used to include an Access object that can be a Datasheet, a Form, a Report, a Module or a Data Access Page into an Electronic Message.

    An Access function (acFunction) does not seem to be a valid type of object for the SendObject method, and moreover the name of the object is left blank ("") in your code.
    Have a nice day!

  9. #9
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    how's about this?
    Code:
    DoCmd.SendObject , , "HTML(*.html)", "a@a.com", "", "", "Test", "This is only a test", True, ""

  10. #10
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can always use Automation to work with Outlook. Here is an example:
    Code:
    Function TestOutlookAutomation()
    
    ' Send an email using Outlook Automation:
    '
        Dim l(0 To 10) As String
        Dim lx As String
        Dim i As Integer
        
    ' You must create a reference to the Outlook library
    ' (For Office 2003: Menu Tools --> References Microsoft Outlook 11.0 Object Library")
    ' if you want to declare Outlook objects like this (early binding):
    '
        Dim appOutlook As Outlook.Application
        Dim oItem As Outlook.MailItem
        Set appOutlook = New Outlook.Application
    
    ' You can also use late binding variables
    ' (no reference needed but less efficient):
    '
    '    Dim appOutlook As Object
    '    Dim oItem As Object
    '    Set appOutlook = CreateObject("Outlook.Application")
        
    ' Create some arbitrary set of lines that will constitute the body of the message:
    '
        For i = 1 To 10
            l(i) = Format(i, "0#") & " ejrioavv effjzfjzfioze,cvze fz ofozeifzjejz."
            lx = lx & l(i) & vbNewLine
        Next i
    
    ' Create an Outlook MailItem (i.e. a new message):
    '
        With appOutlook
            Set oItem = .CreateItem(olMailItem)
    
    ' Fill in some of the new message components:
    '
            With oItem
                .To = "name@domain.com"
                .Subject = "Test Outlook automation"
                .Importance = olImportanceHigh
                .BodyFormat = olFormatHTML
                .Body = lx
    
    ' To display the message:
    '
                .Display
                
    ' To send the message use:
    '
    '            .Save
    '            .Send
    
            End With
        End With
        
    ' Clean up
    '
        Set appOutlook = Nothing
        
    End Function
    Have a nice day!

  11. #11
    Join Date
    Sep 2010
    Posts
    5
    I appreciate your help... I had done the latter part of what you showed in your code. I finally got it to work. The problem with the carriage return not holding had nothing to do with the HTML in outlook. I was using "[ ]" in my string expression as a checkoff box. For some odd reason, when it would initiate the e-mail, the carriage returns would be present, but when you sent it you would lose them. I changed those characters to a "-" and this fixed the problem.

    I will still try what you sent me just in case there is additional text formatting that would require the html setting.

    Thanks

  12. #12
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •