Report output to filepath variable (1 Viewer)

Antony Cole

Registered User.
Local time
Yesterday, 23:42
Joined
Mar 14, 2012
Messages
16
Hi,

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
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:42
Joined
Sep 21, 2011
Messages
14,299
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.
 

Antony Cole

Registered User.
Local time
Yesterday, 23:42
Joined
Mar 14, 2012
Messages
16
Thanks for coming back to me, but unfortuately i'm not that skilled in VBA, hence why I came to ask here.

Thanks

Antony
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:42
Joined
Sep 21, 2011
Messages
14,299
Start using the code tags for code please. Makes it easier to read and keeps indentation. It is the </> icon

Try

Code:
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