Solved Trouble with email command (1 Viewer)

icatterall

New member
Local time
Today, 08:38
Joined
Sep 7, 2023
Messages
5
I have a button that exports a PDF to Outlook. Everything on that end runs perfectly. However, if I choose not to send that email, my database locks up. This is happening on the front end which is locked down. Is there a code that I should put in to stop the macro error due to not sending the email? Thank you for any and all help.
 

June7

AWF VIP
Local time
Today, 05:38
Joined
Mar 9, 2014
Messages
5,472
Is this a macro or VBA? Provide code or attach db to post.
 

icatterall

New member
Local time
Today, 08:38
Joined
Sep 7, 2023
Messages
5
Sorry about that, it is VBA.

Private Sub Command168_Click()
sTo = Me.txt_186
sSubj = "Automated Email of an Observation of " & Me.[FL]
sBody = "Attached is an observation of" & " " & Me.[FL] & ", and it requires your attention."

DoCmd.SendObject acSendReport, "Rpt_MainInstantIncidentEmail", acFormatPDF, sTo, , , sSubj, sBody

End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:38
Joined
Feb 28, 2001
Messages
27,186
You said it was locked down. Therefore your question has to be in two parts. First, can you even work on the modules of that locked-down front end? Second, when you try to send the mail, do you get an Outlook screen to show you the message and let you send it or not as you choose?
 

icatterall

New member
Local time
Today, 08:38
Joined
Sep 7, 2023
Messages
5
@June7 Thank you and I will give that a go.
@The_Doc_Man I do get the pdf file and the message to the Outlook screen. However, let's say that I hit that button mistakenly. If I close out of Outlook without sending it throws an error. This gets me to your other point. I will have to delete the front end, make some changes, and recreate the .accde
 

icatterall

New member
Local time
Today, 08:38
Joined
Sep 7, 2023
Messages
5
Use an error handler like:

Should have Option Explicit at top of every module. This will force all variables to be declared.

To include automatically in new module, from the VBA Editor: Tools > Options > check "Require Variable Declaration".
Will have to manully add to existing modules.
This worked really well, thank you!
 

Users who are viewing this thread

Top Bottom