Print and email with one command button

G

Guest

Newbie here trying to use one command button on a form to first preview a
report and then email the report. Here is my code:

Private Sub Mail_Form_Click()
On Error GoTo Err_mail_form_Click


Dim stDocName As String

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "Speaker Agree", acPreview, , "[ContractID] Like " &
Me![ContractID] & ""
stDocName = "SendToContracts"
DoCmd.RunMacro stDocName
DoCmd.Close acReport, "Speaker Agree"
DoCmd.Close acForm, Me.Name
DoCmd.Quit acQuitSaveAll

Exit_mail_form_Click:
Exit Sub

Err_mail_form_Click:
MsgBox Err.Description
Resume Exit_mail_form_Click

I am getting a message that says application cannot send email. Can anyone
help with what may be wrong with this code. Thanks in advance for the help.
 
B

BruceM

I'll jump in here since nobody else has. I expect that the Macro
SendToContracts (are you sure the spelling agrees with the macro name?) is
how you are sending the e-mail. Does the macro work by itself?
You may be able to perform what you need with SendObject. It allows you to
send report snapshots as e-mail attachments, provided you have a default
e-mail program. It may go something like this:

DoCmd.OpenReport "Speaker Agree", acViewPreview
DoCmd.SendObject acSendReport, "Speaker Agree", acFormatSNP, (e-mail address removed)

I have chosen Report Snapshot as the output format, since you didn't
specify. Note that the Output Format part of the action tends to be buggy,
and there is not a lot of information available about how to fix it. You
may receive Error 2282, telling you that something is missing from the
registry. You may be able to fix the problem with a reinstall of Access,
with optional elements added. Another thing that seems to work is removing
acFormatSNP (or whatever output format you choose) from the code, leaving
the commas in place, and waiting for the prompt to select an output format.
See SendObject in VBA help for more information.
 

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