cricketbird
Registered User.
- Local time
- Today, 01:14
- Joined
- Jun 17, 2013
- Messages
- 118
I'm trying to figure out why I can email a report as a PDF, but not save it as a PDF using the code below?
When I save, I get the dreaded error 2501.
The searching I did for this said to uninstall and reinstall printers (I've done that - seems to have no effect), or took issue with filtering the report with a where clause (but if that was an issue, why does it email a PDF just fine?).
I'd just like to be able to save a report as a PDF to a specified location. I'd appreciate any advice or suggestions. I'm fairly new to VBA.
Thank you!
CB
Developing in: Access 2010; Win7
For use in a mixed 2007/2010 XP/7 environment
When I save, I get the dreaded error 2501.
The searching I did for this said to uninstall and reinstall printers (I've done that - seems to have no effect), or took issue with filtering the report with a where clause (but if that was an issue, why does it email a PDF just fine?).
I'd just like to be able to save a report as a PDF to a specified location. I'd appreciate any advice or suggestions. I'm fairly new to VBA.
Thank you!
CB
Developing in: Access 2010; Win7
For use in a mixed 2007/2010 XP/7 environment
Code:
Private Sub EmailDietCardBtn_Click()
On Error GoTo MyErrorHandler
Me.Refresh
Dim stReport As String
Dim stWhere As String
Dim stSubject As String
Dim stEmailMessage As String
Dim stCaption As String
Dim myPath As String
stEmailMessage = "Please see the attached yada yada yada"
stSubject = "Updates to Diet #" & Me.DIETID '
stReport = "DIET CARD"
stCaption = Me.PATIENT & " " & Me.NOTEID & " #" & Me.DIETID & " " & Format(Now(), "yyyy-mm-dd") & " " & Format(Now(), "hh-nn")
myPath = "J:\Diet Cards\" & stCaption
stWhere = "DietID = " & Me.DIETID '
DoCmd.OpenReport stReport, acViewPreview, "", stWhere, acWindowNormal, ""
Reports![DIET CARD].Caption = stCaption 'Renames The report and add ID fields
'Not all users have Access 2010 so...
If Access.Version > 13 Then
'EMAILING THE PDF WORKS
DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", , , , stSubject, stEmailMessage, True, ""
'BUT SAVING IT TO A SPECIFIED LOCATION DOES NOT
DoCmd.OutputTo acOutputReport, stReport, "PDFFormat(*.pdf)", myPath & ".pdf", False, "", , acExportQualityPrint
Else
DoCmd.SendObject acSendReport, stReport, acFormatXPS, , , , stSubject, stEmailMessage, True, ""
DoCmd.OutputTo acOutputReport, , acFormatXPS, myPath & ".xps", False
End If
Exit Sub
MyErrorHandler:
If Err.Number = 2501 Then
MsgBox "Oops - Error 2501 yet again", vbOKOnly
Exit Sub
Else
MsgBox Err.Number & ":" & Err.DESCRIPTION, vbOKOnly
End If
End Sub