Solved Save report as PDF with query criteria in name, please (1 Viewer)

murray83

Games Collector
Local time
Today, 00:29
Joined
Mar 31, 2017
Messages
728
Hi All

2 questions in one day i am sorry, but in need of a little help this is my code

Code:
Private Sub cmdQuery3_Click()

Dim mypath As String
Dim strReportName As String
Dim sEmailTo As String



    DoCmd.OpenReport "Query3", acViewPreview

    mypath = "G:\GENERAL\STOCK\supplier compliance\BWS Supplier Compliance\BWS Compliance DB\PercentageVsLoad\"

    strReportName = "BWS Percentage Of Faults For" & [Which Date] & ".pdf"
     
    DoCmd.OutputTo acReport, "", acFormatPDF, mypath & strReportName, False


End Sub

which should in theory save the report with the date of the query but it just falls flat and highlights the following point of code, i must admit i took the & bit from my saving for excel so may have got the data wrong

so any help would be great and promise last question for today and this week
 

Attachments

  • yellow.jpg
    yellow.jpg
    49.1 KB · Views: 342
  • error msg.jpg
    error msg.jpg
    21.6 KB · Views: 337

Gasman

Enthusiastic Amateur
Local time
Today, 00:29
Joined
Sep 21, 2011
Messages
14,238
And where is Access meant to get [Which Date] from ?
 

murray83

Games Collector
Local time
Today, 00:29
Joined
Mar 31, 2017
Messages
728
the query which generates the report.

but i guess as your asking that wouldn't work or do i need to put something like report!
 

murray83

Games Collector
Local time
Today, 00:29
Joined
Mar 31, 2017
Messages
728
ok i have managed to get the date to appear in the string for the file name, but due to the date having slashs it wont save ( well thats what i guess the new error msg is )

so how do i change slash for a dot i have changed from short date to medium and long date but both have slashs when it runs to save but the report shows them as medium and long date formats with no slash
 

Attachments

  • error 2.jpg
    error 2.jpg
    21 KB · Views: 337
  • yellow2.jpg
    yellow2.jpg
    51.2 KB · Views: 180

murray83

Games Collector
Local time
Today, 00:29
Joined
Mar 31, 2017
Messages
728
sorry for the tripple post but i have sorted it.

i used the mid function and cut out the slashes to another text box and here is my code now

Code:
Private Sub cmdQuery3_Click()
    
Dim mypath As String
Dim strReportName As String
Dim sEmailTo As String


    DoCmd.OpenReport "Query3", acViewPreview
    mypath = "G:\GENERAL\STOCK\supplier compliance\BWS Supplier Compliance\BWS Compliance DB\PercentageVsLoad\"
    strReportName = "BWS Percentage Of Faults For " & Reports!Query3!txtDay & " - " & Reports!Query3!txtMnth & " - " & Reports!Query3!txtYear & ".pdf"
    DoCmd.OutputTo acReport, "", acFormatPDF, mypath & strReportName, False
  
    
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:29
Joined
Sep 21, 2011
Messages
14,238
I would have just used Repace() with "" or "-" ?
 

Users who are viewing this thread

Top Bottom