Hi after my last question I am trying to separate PDFs in one report based on their Employee ID and have them saved to a folder and named based on their EmployeeID. I have made a query to make a report
I have two codes that I am trying but both keep coming back with an error. This one at
comes back with the error "run time error 3464. data type mismatch in criteria expression" and even adding `& "'"` just keeps creating extra errors...
The other code has an error that pulls up "compile error: variable required - can't assign to this expression" at the
line. The other code is as follows
Any help will be much appreciated! Thank you all in advance.
I have two codes that I am trying but both keep coming back with an error. This one at
Code:
DoCmd.OpenReport "Balance", acViewPreview, , "EmployeeID = " & myrs.Fields("EmployeeID").Value
Code:
Option Compare Database Option Explicit Private Sub cmdprintsep_Click() Dim myrs As DAO.Recordset Dim myPDF, myStmt As String ' Open a record set with a list of invoice number to print myStmt = "SELECT distinct EmployeeID from queBalance" Set myrs = CurrentDb.OpenRecordset(myStmt) ' For each invoice, print in a .pdf Do Until myrs.EOF ' Set the output path of your PDF file invoice myPDF = "C:\Users\user\Desktop\reports\" & Format(myrs.Fields("EmployeeID"), "000000") & ".pdf" ' Open the report with the proper where condition DoCmd.OpenReport "Balance", acViewPreview, , "EmployeeID = " & myrs!EmployeeID & " " strFilter = “EmployeeID = “ & myrs!EmplyeeID ' Generate the output in pdf DoCmd.OutputTo objectType:=acOutputReport, objectName:="Balance", outputformat:=acFormatPDF, outputfile:=myPDF, outputquality:=acExportQualityPrint DoCmd.Close ' Close the report rs.MoveNext ' read next Loop ' some cleanup myrs.Close Set myrs = Nothing End Sub
Code:
For Each [EmployeeID] In [EmployeeID]
Code:
Dim rs As DAO.Recordset Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT [EmployeeID] FROM queBalance") Dim MyPath As String Dim MyFilename As String MyPath = "C:\Users\user\Desktop\reports\" 'Loop structure may vary depending on how you obtain values For Each fGetID In EmployeeID MyFilename = "FI" & EmployeeID & ".pdf" 'Open report preview and auto-save it as a PDF DoCmd.OpenReport "Balance", acViewPreview, , "EmployeeID = " & EmployeeID & "'" DoCmd.OutputTo acOutputReport, "", acFormatPDF, MyPath & MyFilename, False DoCmd.Close acReport, "Balance" Next [EmployeeID] End Sub
Comment