iainmacleod
asked on
The sendobject action was cancelled
I am using a button to send an email and have the problem when closing the email rather than sending.
I cannot seem to figure out other code examples found so hoped that by showing my modest code might persuade someone to offer me a little assistance.
Thanks in advance.
Private Sub emailcertcmd_Click()
Dim dbs As Database, customers As Recordset, certemail As Variant, stDocName As String
Set dbs = CurrentDb
stDocName = "Main Certificateemail"
Set cust = dbs.OpenRecordset("custome rs", dbOpenDynaset)
On Error Resume Next
cust.MoveFirst
Do Until cust.EOF
If Me.Accno = cust![Account No] Then
certemail = cust![certemail]
End If
cust.MoveNext
Loop
DoCmd.SendObject acSendReport, "Main Certificateemail", acFormatPDF, certemail, , , "Your Freightnet (RASCO) Ltd REST Certificate is attached", "Please find your Certificate attached", True
DoCmd.RunMacro ("main printcert")
db.Close
Set db = Nothing
End Sub
I cannot seem to figure out other code examples found so hoped that by showing my modest code might persuade someone to offer me a little assistance.
Thanks in advance.
Private Sub emailcertcmd_Click()
Dim dbs As Database, customers As Recordset, certemail As Variant, stDocName As String
Set dbs = CurrentDb
stDocName = "Main Certificateemail"
Set cust = dbs.OpenRecordset("custome
On Error Resume Next
cust.MoveFirst
Do Until cust.EOF
If Me.Accno = cust![Account No] Then
certemail = cust![certemail]
End If
cust.MoveNext
Loop
DoCmd.SendObject acSendReport, "Main Certificateemail", acFormatPDF, certemail, , , "Your Freightnet (RASCO) Ltd REST Certificate is attached", "Please find your Certificate attached", True
DoCmd.RunMacro ("main printcert")
db.Close
Set db = Nothing
End Sub
cust.MoveFirst
Do Until cust.EOF
If Me.Accno = cust![Account No] Then
certemail = cust![certemail]
exit do '<< ADD this , to end the search once you found the email
End If
cust.MoveNext
Loop
ASKER
Thanks for the swift reply.
The error handler works perfectly on my workstation running full Access (I do get an error telling me an object is required after the "Email not sent" message, however I have just realised that once i put this in a runtime version i still get the Send object error priot to the "email not sent" msg.
The error handler works perfectly on my workstation running full Access (I do get an error telling me an object is required after the "Email not sent" message, however I have just realised that once i put this in a runtime version i still get the Send object error priot to the "email not sent" msg.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much for your advice, gratefully recieved. I am finding this coding really useful and effective but clearly i lack some of the basics...
Private Sub emailcertcmd_Click()
Dim dbs As Database, customers As Recordset, certemail As Variant, stDocName As String
Set dbs = CurrentDb
stDocName = "Main Certificateemail"
Set cust = dbs.OpenRecordset("custome
On Error Goto EH '<---- Change this to send errors to an error handler
cust.MoveFirst
Do Until cust.EOF
If Me.Accno = cust![Account No] Then
certemail = cust![certemail]
End If
cust.MoveNext
Loop
DoCmd.SendObject acSendReport, "Main Certificateemail", acFormatPDF, certemail, , , "Your Freightnet (RASCO) Ltd REST Certificate is attached", "Please find your Certificate attached", True
DoCmd.RunMacro ("main printcert")
db.Close
Set db = Nothing
Exit sub '<---- Exit if no errors
EH: '<--- error handler
if err.number = 2501 then
msgbox "The email was not sent"
resume next
else if
msgbox Err.number & ": " & err.description
resume next
end if
End Sub