Emailing from Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings...

I have a form that contains a current user field. Is it possible to write a
code to send an email using the email addressed based on a field? If so,
what would be the code?

Thanks,
Alfia
 
alfiajamel said:
Greetings...

I have a form that contains a current user field. Is it possible to write
a
code to send an email using the email addressed based on a field? If so,
what would be the code?

Thanks,
Alfia

Check out the DoCmd.SendObject method.

Carl Rapson
 
Good Morning,

This is the code that I am using:

Private Sub cmdSubmit_Click()
DoCmd.SendObject acReport, "qryMovementPreviewReport",
"SnapshotFormat(*.snp)", "[Forms]![frmGeneralMovement]![txtCurrentEmail]",
"[Forms]![frmGeneralMovement]![txtNewEmail]", "", "Movement Review", "Please
review the movement listed below.", False, ""

End Sub


It is giving me an error message stating the email address is unknown.
Would someone be able to tell me what's wrong with the code. Also, how could
I generate an error message so that my usere would not be given the option to
debug?

Thanks,
Alfia
 
alfiajamel said:
Good Morning,

This is the code that I am using:

Private Sub cmdSubmit_Click()
DoCmd.SendObject acReport, "qryMovementPreviewReport",
"SnapshotFormat(*.snp)", "[Forms]![frmGeneralMovement]![txtCurrentEmail]",
"[Forms]![frmGeneralMovement]![txtNewEmail]", "", "Movement Review",
"Please
review the movement listed below.", False, ""

End Sub


It is giving me an error message stating the email address is unknown.
Would someone be able to tell me what's wrong with the code. Also, how
could
I generate an error message so that my usere would not be given the option
to
debug?

Thanks,
Alfia

When you do this:

"[Forms]![frmGeneralMovement]![txtCurrentEmail]"

you're literally sending the string
"Forms![frmGeneralMovement]![txtCurrentEmail]" as the email address. What
you want is the contents of the txtCurrentEmail field, so remove the quotes:

DoCmd.SendObject acReport, "qryMovementPreviewReport",
"SnapshotFormat(*.snp)", [Forms]![frmGeneralMovement]![txtCurrentEmail],
[Forms]![frmGeneralMovement]![txtNewEmail], "", "Movement Review", "Please
review the movement listed below.", False, ""

Note that if this code is running in the form frmGeneralMovement, you can
simplify this as:

DoCmd.SendObject acReport, "qryMovementPreviewReport",
"SnapshotFormat(*.snp)", Me.txtCurrentEmail, Me.txtNewEmail, "", "Movement
Review", "Please review the movement listed below.", False, ""

As for your other question, you should be able to do something like:

On Error Resume Next
DoCmd.SendObject ...
If Err.Number <> 0 Then
' Do error handling here
End If

Carl Rapson
 
Back
Top