Send email

  • Thread starter Thread starter julieroy
  • Start date Start date
J

julieroy

Guest
As a newbie, I want to create a button that will send data (don't care if it is a report in pdf, written as text into the email, as an excel sheet, etc) to the program owner and data owner when the record has been updated. I only want to send the info for the current record.

I have copied the code for sending an email from another post, but am unsure how to include fields from the current record. The "tblreportlist" has a field ("to") for the email address that I would also like to autopopulate with the program and data owners names.

Sample fields to include are "category","campaign name" from the table "campaign data"

Thanks for the help!
Julie
:confused:
 
Bonjour Julie,
Here it is:
DoCmd.SendObject acReport, [ReportName], [ReportFormat],[SendToName],[SendCopyTo],[SendInvisibleCopyTo],[MailSubject],[Message]
I'm not sure about what you asked. If you're looking for the active user, and have security on, then you can use "CurrentUser".
 
For another example, lets say that you have three textbox fields on your form.

The fields are named txtEmailTo, txtSubject, and txtMessage. You can fill your SsendObject command with values from the form fields with the following code.
Code:
Dim strToField as String
Dim strSubject as String
Dim strMessage As String

' use the Me.[FieldName] to get the value from any field.

strToField = Me.txtEmailTo
strSubject = Me.txtSubject
strMessage = Me.txtMessage

DoCmd.SendObject , , , strToField, , , strSubject, _
    strMessage, False
All you need to do is put the code behind a command button on your form and change the txtbox field names to match your own. Post back if you have more questions about this.

One more note about this is that you can view the email before they are sent by changing the False to True at the end of the SendObject statement.
 
Last edited:
I have tried this code but everytime I try to send the mail i get a
'Runtime error 2501' The SendObject action was cancelled. I also want to know how to put information from more that one field into the main body of the email. Is this at all possible. Please help.
 
I have tried this code but everytime I try to send the mail i get a
'Runtime error 2501' The SendObject action was cancelled. I also want to know how to put information from more that one field into the main body of the email. Is this at all possible. Please help.
 
You may want to check your email settings. I have been playing around with sendobject, and I know when I don't have an email account set up that it would take me to a wizard. When I exited the wizard, it would give me the same error. So check your email settings.

As for the information from more than one field, that is not too hard. in the code above, you can append more to your strMessage. I would do it like:

strMessage = field1.text
strMessage = strMessage & field2.text
strMessage = strMessage & vbNewLine & field3.text

fields one and two should be on the same line, and then field 3 should be on a new line. In the end you will have one big string as your message. Hope that helps,

Brian
 

Users who are viewing this thread

Back
Top Bottom