Report output to filepath variable (1 Viewer)

Antony Cole

Registered User.
Mar 14, 2012

Please can someone help me where i'm going wrong with the code below. I'm trying to output a report to PDF from a form and save it to the current windows logged on users profile in Teams, but I keep getting a runtime 2501 error the outputto action was cancelled. Thanks in advance

Private Sub Command115_Exit(Cancel As Integer)
Dim filename As String
Dim strUserName As String, strPath As String
Dim reportName As String
Dim Criteria As String

filename = Me.[Prepared By] & "-" & "GFM" & "" & Me.[Quote Ref] & "-" & Me.[Minor Works Title]
strUserName = Environ("username")
strPath = "C:\Users\& Strusername &\GRAHAM\GFM Team - Documents\Quotes" & filename & ".PDF"
reportName = "QuoteDetailsT1"
Criteria = "[Quote Ref] = " & Me.[Quote Ref]

DoCmd.OpenReport reportName, acViewPreview, , Criteria, acHidden
DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, strPath, True
DoCmd.Close acReport, reportName, acSaveNo

End Sub
Try debug.print on your strPath and it should be obvious.
I would do the same for filename.
This is debugging 101.

Tip: Your concatenation is way off.
Thanks for coming back to me, but unfortuately i'm not that skilled in VBA, hence why I came to ask here.


Start using the code tags for code please. Makes it easier to read and keeps indentation. It is the </> icon


FileName = Me.[Prepared By] & "-GFM" & Me.[Quote Ref] & "-" & Me.[Minor Works Title]
Strusername = Environ("username")
strPath = "C:\Users\" & Strusername & "\GRAHAM\GFM Team - Documents\Quotes\" & FileName & ".PDF"

Still use Debug.Print to ensure it is correct

Users who are viewing this thread

Top Bottom