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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending e-mail question

Status
Not open for further replies.

RandyMyers

IS-IT--Management
Apr 28, 2004
85
US
I am using the SendObject function (macro) to e-mail from a form. Is there any way to insert a value from a field on the form into the To: slot in the e-mail. I have tried the usual [Forms]![FormName]![FieldName] and an error stating that it is not a valid e-mail address occurs. I have tried enclosing the field reference in quotations and perenthesis. Nothing seems acceptable other than a hard coded e-mail address. It appears as if the slot can only have an e-mail address inserted, and not a reference to a field on a form.

I really would prefer not to have to hard code the address but instead have the system pick by the users name where to send the e-mail.

Any ideas?
 
It should work as you describe it. You should double check everything to make sure you have the reference correct, and that the form is open and poplulated with a value when you try and run it. You could try using the SendObject method in a VBA module. That should work the same way.


Paul
 
The e-mail macro is ran from an E-Mail button on the form. The field referenced is a combo box and the e-mail address is the third column on the combo box. I have also tried having a field on the form that gets set with the e-mail address (however the referencing a combo box column has always seem to work in the past). The line I set in the To slot of the SendObject macro is:

[Forms]![frmWorkOrders]![WOITStaff].[Column](2)

The form name is frmWorkOrders and the combo box field name is WOITStaff. The box has three columns, Staff ID, Staff name and E-Mail address, all being pulled from a Staff table through an IT Staff choice query.

When I click the button Outlook attempts to send the e-mail but comes up with the error:

Unknown message recipient(s); message was not sent

However, if I hard code the exact same e-mail address is the To slot of the SendObject macro it works just fine.

Any other thoughts?
 
Here is the help file text concerning this. Does this make sense or does it appear that this is s special situation where only hard codign addresses are allow?

"The recipients of the message whose names you want to put on the To line in the mail message. If you leave this argument blank, Access prompts you for the recipients' names.
Separate the recipients' 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 Microsoft Windows Control Panel. If the mail application can't identify the recipients' names, the message isn't sent and an error occurs."
 
Randy,

I currently use a VBA Sub under a command button. Here is the basic code...
Code:
Private Sub cmdEmail_Click()
   
        Dim strToDefault As String  'variable string to hold the name

       strToDefault = Me!ToName  'setting the variable

DoCmd.SendObject , , , strToDefault, , , "the subject is here", "this is the message body"

End Sub

cmdEmail is the name of the button
Me!ToName it the name of the control on the form with the name of the recipient.

Hope this helps

Donald M
 
Try putting an equals sign(=) in front of your forms reference in the To argument. When I tried using a macro (MsgBox) to return a column in a combo box, if my form reference was
=Forms![WorkOrders]![DepartmentID].Column(0)
I got what I expected. If I used
Forms![WorkOrders]![DepartmentID].Column(0)
the macro returned
Forms![WorkOrders]![DepartmentID].Column(0)
for the value.

Paul
 
Thank you for all the responses. Inserting an = sign worked. I don't know how I missed that one :)....


"embarrassed" :)

Thanks again...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top