Email code

O

OscarC

Hello,

I have a form with a button on that generates a report and creates a
new email message, using the following code:

Private Sub cmd_Email_Report_Click()
On Error GoTo Err_cmd_Email_Report_Click

Dim stDocName As String

stDocName = "rpt_Email_Notification"
DoCmd.SendObject acReport, stDocName, acFormatSNP, _
"(e-mail address removed)", , , _
"Subject", "Message Text", True



Exit_cmd_Email_Report_Click:
Exit Sub

Err_cmd_Email_Report_Click:
MsgBox Err.Description
Resume Exit_cmd_Email_Report_Click

End Sub


I would like to modify this code so that the code will get the email
address to send the report to from a table or query. How would I do
this?

Thanks,


Michael
 
D

Dirk Goldgar

OscarC said:
Hello,

I have a form with a button on that generates a report and creates a
new email message, using the following code:

Private Sub cmd_Email_Report_Click()
On Error GoTo Err_cmd_Email_Report_Click

Dim stDocName As String

stDocName = "rpt_Email_Notification"
DoCmd.SendObject acReport, stDocName, acFormatSNP, _
"(e-mail address removed)", , , _
"Subject", "Message Text", True



Exit_cmd_Email_Report_Click:
Exit Sub

Err_cmd_Email_Report_Click:
MsgBox Err.Description
Resume Exit_cmd_Email_Report_Click

End Sub


I would like to modify this code so that the code will get the email
address to send the report to from a table or query. How would I do
this?

Thanks,


Michael

Something along the lines of:

Dim stDocName As String
Dim varEmail As Variant

stDocName = "rpt_Email_Notification"

varEmail = DLookup("EmailAddress", "People", _
"PersonID=" & Me.PersonID)

If IsNull(varEmail) Then
MsgBox "Can't send e-mail; no address in People table!"
Else
DoCmd.SendObject acReport, stDocName, acFormatSNP, _
varEmail, , , _
"Subject", "Message Text", True
End If
 
O

OscarC

Something along the lines of:

Dim stDocName As String
Dim varEmail As Variant

stDocName = "rpt_Email_Notification"

varEmail = DLookup("EmailAddress", "People", _
"PersonID=" & Me.PersonID)

If IsNull(varEmail) Then
MsgBox "Can't send e-mail; no address in People table!"
Else
DoCmd.SendObject acReport, stDocName, acFormatSNP, _
varEmail, , , _
"Subject", "Message Text", True
End If


Thanks - does exactly what I want!

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top