ARGH! Using Sendobject to send email.

TomH

Registered User.
Local time
Today, 18:38
Joined
Nov 3, 2008
Messages
111
Hi all. New ID, but not new to the forums. Need some help on syntax. Have read through a number of searches and just can't seem to get this to work.

I have a form called "NamesForm"
On that form, I have fields called "SalesRep", "RepEmail", "OfficeMgr", "MgrEmail". I also have a button called "EmailButton".

On clicking EmailButton, I want an email to open in Outlook Express that prepopulates the To: field with the "RepEmail" value, and the cc: field with the "MgrEmail" value.

I have tried every syntax I can think of to get this done, and I simply cannot get to work. I can get related processes, such as if the email fields are blank to give an error message, etc, but the SendObject process is giving me fits.

Any help is greatly appreciated.

Tom
 
Your syntax should follow this....
DoCmd.SendObject [objecttype],[objectname],[outputformat],[to],[cc],[bcc],[subject],[messagetext],[editmessage],[templatefile]
 
Thanks, I have that already... it shows on the screen as I type in the code. But, I need help with each entry that should go into each argument, and especially the beginning and ending syntax and punctuation of the SendObject command. THANKS.
 
Let's say on your form you had a field called "SalesRep". Now, you are calling that a field - do you mean a control that is bound to that field? A text control can have a different name than the bound field. Let's assume that they are both the same name ..."SalesRep" and you wanted this to go into the To: of the e-mail.

In the command line for the send object to reference the control on the form that has the information you want it will look like ...

Syntax: ..., [To], ...

Reference: ..., Me.SalesRep, ....


Here is a post where I helped someone work it out a bit more with some sample code:
http://www.access-programmers.co.uk/...ht=send+report

-dK
 
dkinley: You're right... I should definitely use the correct terminology. Yes... my form control is bound to the table field and is of the same name.

Tried your link, but it gives an error.

I'm pretty sure I can fill in the appropriate arguments with the names of the controls... but specifically I am having trouble with the punctuation. Where do I use brackets, commas, parentheses, etc? Nothing I try works... for example, I tried a close-parentheses at the end, but got an error. I tried leaving it out and got another error. I've used vba before, but haven't had this type of trouble before.

So, for my example:
DoCmd.SendObject [objecttype],[objectname],[outputformat],[to],[cc],[bcc],[subject],[messagetext],[editmessage],[templatefile]

Should be(?):
DoCmd.SendObject [objecttype],,,Me.RepEmail,Me.MgrEmail,,,,,

First, not sure what [objecttype] should be, and then there's that [templatefile] argument hanging at the end after the last comma.
Do I need to create an object first before using this command? Man, I feel stupid here!!
 
You should post the code you have...Then someone could see the error. Heres a real example...
Code:
Dim stDocName As String
  
    stDocName = "rptClientIssue"
    
   DoCmd.SendObject acSendReport, stDocName, "SnapshotFormat(*.snp)", [EmployeeEmail], "", "", [ClientName] & "/ Issue ID-" & [IssueID], "Client Issue", False, ""
This sends a mail in report format (acSendReport) named (rptClientIssue) to an address in a textbox named, [EmployeeEmail] the subject line is filled with [ClientName] &"/ Issue ID-" & [IssueID] the message text is "Client Issue" and so on.... This is on the OnClick event of a button.
 
Strange ... recopying link for you ..

http://www.access-programmers.co.uk/forums/showthread.php?t=155673&highlight=send+report

Here is a sample of the code:

Code:
Dim sSubject As String
Dim sToName As String
Dim sDocName As String
 
sDocName = "rptReportName"
sSubject = "New Record Added for " & Me.ReferenceControlName
sToName =  Me.txtEmailControl
 
DoCmd.RunCommand acCmdSaveRecord
DoCmd.SendObject acSendReport, sDocName, acFormatRTF, _
sToName, , , sSubject, , False

I think the problem is your arguments, you can't leave the argument name between the commas. Here, in this sample, I created variables to help keep everything straight. I assigned the variable the value of the control and then used the variable as the argument. You can either put in nothing in which the argument will be the default (sometimes nothing as in the code sample for the cc/bcc) or a true/false. In the above, I put in False as the last argument so the email would just send instead of opening for editing purposes. Recheck your arguments and ensure the default is fine or adjust accordingly.

-dK
 

Users who are viewing this thread

Back
Top Bottom