SendObject unusual syntax: want to adapt but don't understand it!

Abiart

Registered User.
Local time
Today, 01:27
Joined
May 17, 2006
Messages
27
Hi everyone,

This is a small part of a bigger problem, but it's one step at a time so here goes:

Code:
            DoCmd.SendObject outputformat:=acFormatTXT, _
                            To:=rst(EmailAddressField), _
                            subject:=Me.Controls(MsgSubjectField), _
                            MessageText:=strMsgToSend, _
                            EditMessage:=False
        
            If Err.Number <> 0 Then ' SendObject raised an error
                bSendError = True
                Err.Clear
            End If

How does this fit into the syntax:

Code:
SendObject (Object Type,Object Name,Output Format,To,Cc,Bcc,Subject,Message Text,Edit Message,Template File)

When, as far as I know, a normal SendObject procedure looks like this:

Code:
On Error GoTo DistributorsSummary_Err

    DoCmd.SendObject acReport, "Distributors Summary", "SnapshotFormat(*.snp)", "example@domain.com", "", "", "Example Email", "Dear such and such please find attached etc.", False, ""
    
DistributorsSummary_Exit:
    Exit Function

DistributorsSummary_Err:
    MsgBox Error$
    Resume DistributorsSummary_Exit

End Function


The reason I ask is because I want to take some of the elements from the second procedure, namely attaching a report snapshot, to the first one, which forms a small part of some code in my database.

I realise it is due to the fact that several of the field names are defined at the beginning of the code, but I'm not sure how to adapt it.

Thanks in advance!
 
re:

Hi,
What's different in the syntax?
I think the person who coded this part did not realize that the output format argument of the sendobject method does not refer to the actual email, but rather an attachment. Sendobject can only create plain text emails so that isn't neccissary in that case. Furthernore the to, subject, and messageText arguments are filled with reference values from somewhere else. The email address is probably from a recordset which is open before this code (maybe a loop to loop through a table of emails to send many emails in a row). The subject must be a control on a form somewhere and the message variable must reference something else before this code, too. Besides that using error handling is actually a good thing and you should implement that as well. For one thing the code should actually throw an error if the email is being closed and not send (try it out).
HTH
Good luck
 
if you have multiple parameters in a function call you can either string them together, using commas as placeholders

eg docmd.openreport "myname",,,,"where condition" etc
or specify the parameters you need to set individually with the name colon syntax as in

DoCmd.SendObject outputformat:=acFormatTXT, _
To:=rst(EmailAddressField), _
subject:=Me.Controls(MsgSubjectField), _
MessageText:=strMsgToSend, _
EditMessage:=False


however you can't say
rst(emailaddressfield), you need to say
rst!emailaddressfield

and you might be better with
subject:=MsgSubjectField
 
Thanks guys for all your advice and suggestions - I hadn't come across name colon syntax before as Gemma mentioned, but now I've used/edited it and it seems quite handy!
 

Users who are viewing this thread

Back
Top Bottom