Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to set "from" in SendObject method? 3

Status
Not open for further replies.

Pampers

Technical User
Apr 7, 2004
1,300
AN
Hi everyone,
I want to sent an email (fax) with an attachment by using docmd.sendobject. All is fine, but I also must include the "from"-field. How can this be done. I don't see this option in the SendObject method.

Code:
DoCmd.SendObject acSendReport, , acFormatHTML, , EmailAddress2, , , "Curline Invoice", , , True


Pampers [afro]
Just let it go...
 
As far as I recall, SendObject uses your default program and account. Is it my imagination or have you got too many commas? Is the final True a Template or an EditMessage? If the latter, is changing the name at that point an option? Or Outlook? [ponder]
 
Hi Remou,
Tnx for your reply. No, the number of comma's is right. The last true is the EditMessage option.

It is working ok. But the code actually sents a fax message through outlook. But outlook is configired in such a way that you have to use a specific "From:" to use this fax-option. If I leave "From:" empty, it takes my emailaddress (default), tries to send it and gives an error-message because I'm not allowed the sent faxes.

But maybe there is a way to tell outlook that the default emailaddress in temperarly someone else?? Wouldn't know how to code that tough...

Pampers [afro]
Just let it go...
 
Did you see:
faxing (SendObject) w/ Outlook 2k / Win 2k ???
thread703-715226
 
Tnx for the link,
I haven't seen it, and can use it for the looping. I think I use the same Sendobject-routine as in the example.

Code:
EmailAddress2 = "[Fax:" & Me.EmailAddress & "]"
DoCmd.SendObject acSendReport, , acFormatHTML, , EmailAddress2, , , "Curline Invoice", , , True

But the problem remains, that one can not set the "From" part in the email.


Pampers [afro]
Just let it go...
 
I'm fairly certain that the SendObject method doesn't allow you to specify the "From" field, you'd have to find another method for doing this, maybe there is a custom API call out there somewhere?

From the Microsoft VBA Help file for Access:
The SendObject method carries out the SendObject action in Visual Basic.

expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)
expression Required. An expression that returns one of the objects in the Applies To list.

ObjectType Optional AcSendObjectType.

AcSendObjectType can be one of these AcSendObjectType constants.
acSendDataAccessPage
acSendForm
acSendModule
acSendNoObject default
acSendQuery
acSendReport
acSendTable

ObjectName Optional Variant. A string expression that's the valid name of an object of the type selected by the objecttype argument. If you want to include the active object in the mail message, specify the object's type with the objecttype argument and leave this argument blank. If you leave both the objecttype and objectname arguments blank (the default constant, acSendNoObject, is assumed for the objecttype argument), Microsoft Access sends a message to the electronic mail application without an included database object. If you run Visual Basic code containing the SendObject method in a library database, Microsoft Access looks for the object with this name first in the library database, then in the current database.

OutputFormat Optional Variant.

To Optional Variant. A string expression that lists the recipients whose names you want to put on the To line in the mail message. Separate the recipient names you specify in this argument and in the cc and bcc arguments with a semicolon (;) or with the list separator set on the Number tab of the Regional Settings Properties dialog box in Windows Control Panel. If the recipient names aren't recognized by the mail application, the message isn't sent and an error occurs. If you leave this argument blank, Microsoft Access prompts you for the recipients.

Cc Optional Variant. A string expression that lists the recipients whose names you want to put on the Cc line in the mail message. If you leave this argument blank, the Cc line in the mail message is blank.

Bcc Optional Variant. A string expression that lists the recipients whose names you want to put on the Bcc line in the mail message. If you leave this argument blank, the Bcc line in the mail message is blank.

Subject Optional Variant. A string expression containing the text you want to put on the Subject line in the mail message. If you leave this argument blank, the Subject line in the mail message is blank.

MessageText Optional Variant. A string expression containing the text you want to include in the body of the mail message, after the object. If you leave this argument blank, the object is all that's included in the body of the mail message.

EditMessage Optional Variant. Use True (–1) to open the electronic mail application immediately with the message loaded, so the message can be edited. Use False (0) to send the message without editing it. If you leave this argument blank, the default (True) is assumed.

TemplateFile Optional Variant. A string expression that's the full name, including the path
 
tnx kjv1611,
Yes you right. Tnx for the response. I start looking for an API...


Pampers [afro]
Just let it go...
 
Have a look at the last post here:
programming ms outlook and ms access, very complicated problem
thread705-579014
It mentions a From, though not with SendObject.
 
Hi Remou,
Tnx for the reference. Looks interesting. Specially the code:
Code:
With objOutlookMsg
    If Not IsMissing(FromAddr) Then
        .SentOnBehalfOfName = FromAddr
    End If

I'm gonna check it out.


Pampers [afro]
Just let it go...
 
I also found this:

Title: Setting the From (sender) on a message
Description: Outlook provides no direct way to set the From value for all messages. If the user has Outlook 2002/3 and is not using WordMail as the editor, however, you can use the code below to set the sending account using CommandBars techniques.
Date: 13-May-2005 03:57
Code level: intermediate
Code area: Outlook Expert Techniques
Posted by: Sue Mosher

Code:
Function Set_Account(ByVal AccountName As String, M As Outlook.MailItem) As String
    Dim OLI As Outlook.Inspector
    Dim strAccountBtnName As String
    Dim intLoc As Integer
    Const ID_ACCOUNTS = 31224

    Dim CBs As Office.CommandBars
    Dim CBP As Office.CommandBarPopup
    Dim MC As Office.CommandBarControl

    Set OLI = M.GetInspector
    If Not OLI Is Nothing Then
        Set CBs = OLI.CommandBars
        Set CBP = CBs.FindControl(, ID_ACCOUNTS)
        If Not CBP Is Nothing Then
            For Each MC In CBP.Controls
                intLoc = InStr(MC.Caption, " ")
                If intLoc > 0 Then
                    strAccountBtnName = Mid(MC.Caption, intLoc + 1)
                Else
                    strAccountBtnName = MC.Caption
                End If
                If strAccountBtnName = AccountName Then
                    MC.Execute
                    Set_Account = AccountName
                    GoTo Exit_Function
                End If
            Next
        End If
    End If
    Set_Account = ""

Exit_Function:
    Set MC = Nothing
    Set CBP = Nothing
    Set CBs = Nothing
    Set OLI = Nothing
End Function


Pampers [afro]
Just let it go...
 
Having been through the hassles of trying to get emails to behave across multiple environments I use these two modules.

Module 1 – Using CDO Library

You need to add CDO for windows 2000 library to the references

Then you can use this code
Code:
Sub emailfunction(FromAddress As String, ToAddress As String, Mysubject As String, mybody As String, attm1 As String, attm2 As String, attm3 As String, attm4 As String)
' this is the send module which sends immeditally
Dim iCfg As Object
Dim iMsg As Object
Dim attm
Set iCfg = CreateObject("CDO.Configuration")
Set iMsg = CreateObject("CDO.Message")
With iCfg.Fields
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "smtpServer" ' need to know this to use
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendemailaddress")[/URL] = FromAddress
.Update
End With
With iMsg
                 If attm1 <> "nil" Then
                 attm = attm1
                 .AddAttachment attm
                 End If
                 If attm2 <> "nil" Then
                 attm = attm2
                 .AddAttachment attm
                 End If
                 If attm3 <> "nil" Then
                 attm = attm3
                 .AddAttachment attm
                 End If
                 If attm4 <> "nil" Then
                 attm = attm4
                 .AddAttachment attm
                 End If

.Configuration = iCfg
.Subject = Mysubject
.To = ToAddress
.HTMLBody = mybody
.Send

End With

Set iMsg = Nothing
Set iCfg = Nothing

End Sub


Method 2 – Using Outlook library – twisting the reply to address

'Standard email procedure for outlook emails

Code:
Sub emailfunction(FromAddress As String, ToAddress As String, Mysubject As String, mybody As Variant, attm1 As String, attm2 As String, attm3 As String, attm4 As String)
'this is the send module
'Sending Email
Dim objOutlook As New Outlook.Application
Dim objRem As MailItem
Dim attm
Dim strMessage As String

' additional bits for setting reply address, cant set from address in outlook code this bit of code
’ sets the reply to address

Dim colReplyRecips As Recipients
Dim objReplyRecip As Recipient

' sets up email
Set objRem = objOutlook.CreateItem(olMailItem)
' reply address
Set colReplyRecips = objRem.ReplyRecipients
Set objReplyRecip = colReplyRecips.Add(FromAddress)
objReplyRecip.Resolve

                    objRem.To = ToAddress
                    objRem.Subject = Mysubject
                    ' adds attachments
                    
                 If attm1 <> "nil" Then
                 attm = attm1
                 objRem.Attachments.Add attm
                 End If
                 If attm2 <> "nil" Then
                 attm = attm2
                 objRem.Attachments.Add attm
                 End If
                 If attm3 <> "nil" Then
                 attm = attm3
                 objRem.Attachments.Add attm
                 End If
                 If attm4 <> "nil" Then
                 attm = attm4
                 objRem.Attachments.Add attm
                 End If

                    
                    objRem.Body = mybody 
                    objRem.Send
End Sub

Hope this helps
 
Hi Irish1957,
Many tnx for the code. Just came back from a little tour through New Orleans. Haven't had time to put to code work, yet. Keep you posted.

Pampers [afro]
Just let it go...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top