Hey guys i have the following code where depending on an option i choose off a form exports a report to various options.
All works ok until i try to use option 4 first then repeat using option 3 at which point i geta runtime 2501 error
So any ideas why would be great.
All works ok until i try to use option 4 first then repeat using option 3 at which point i geta runtime 2501 error
So any ideas why would be great.
Code:
Select Case rpttype
Case Is = 1
'this option outputs the the relevant report at 100% zoom in print preview mode
DoCmd.OpenReport strrpt, acViewPreview
DoCmd.RunCommand acCmdZoom100
DoCmd.Maximize
Case Is = 3
'this option creates the report then outputs it to a pdf format
'the file is titled the name of the report and todays date formatted to ddmmyy
'DoCmd.OpenReport strrpt, acViewPreview
DoCmd.OutputTo acOutputReport, strrpt, acFormatPDF, "C:\TFRS REPORTS\" & strrpt & today & ".PDF"
DoCmd.Close
Case Is = 4
'this option outputs the report to a pdf document then emails it to certain email addresses
Set objMessage = CreateObject("CDO.Message")
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.bigpond.com"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.subject = subject
sendto = InputBox("Enter email addresses with a ; as the seperator", _
"EMAIL ADDRESSES", "jason.smith@tfrs.com.au")
objMessage.from = "TFRS CUSTOM REPORTS <tfrsreports@tfrs.com.au>"
objMessage.to = sendto
objMessage.Bcc = ""
objMessage.CC = ""
objMessage.TextBody = "TFRS CUSTOM REPORTS"
DoCmd.OutputTo acOutputReport, strrpt, acFormatPDF, "C:\TFRS REPORTS\" & strrpt & today & ".PDF"
DoCmd.Close
objMessage.AddAttachment "C:\TFRS REPORTS\" & strrpt & today & ".PDF"
objMessage.Send
End Select