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 do I send a simple email out of VBA via command button click

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
I need to send a simple email message incorporating some data off of a form when the user clicks a command button. Formatting is not an issue here, I need the most generic options possible.

All I really need is how to setup the To, Subject and Body fields. A CC and BCC would be nice but not a requirement. Since search is down, can someone point me or post a little blurb of code to get me started?

Thanks in advance for the help!
 
Look at the SendObject method.

You can specify everything you mentioned.
 
Here is what I did for anyone else's reference:

Private Sub cmdEMail_Click()
Dim strMessage As String
Dim strSubject As String
Dim varSendTo As Variant
strMessage = "Below is the report you requested" _
& vbCrLf & vbCrLf & mstrReport
strSubject = "Report for " & mstrReport
If vbNo = MsgBox("Select recipients (defaults " _
& "used if no selected)", vbYesNo + vbQuestion) Then
varSendTo = "validDefaultEmailAddress"
End If
DoCmd.SendObject , , , varSendTo, , , strSubject, _
strMessage
End Sub

By using a variant for the To list, it will be empty if the user answers Yes to the select recipient prompt which will cause it to prompt for recipients.

Is there a way to automatically send the message if no recipients need to be added?

Thanks in advance for any help!

PS. John, thanks again for the help. If you send an email address to SBendBuckeye2000@yahoo.com and post again so I know to check it, I will be happy to send you a copy of the little utility I'm working on which incorporated the above into an email notification option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top