All using Access 2016. I am trying to export a rpt to pdf but want it to create separate files filtered on cust_id. But when I run the code; it throws an error: sub or function not defined. My code is as follows:
First; Declared a variable in a Module (as Public):
Code:
Option Compare Database
Public strRptFilter As String
In the Open event of my report:
Code:
If Len(strRptFilter) <> 0 Then
Me.Filter = strRptFilter
Me.FilterOn = True
End If
In the Close event of the report:
Code:
strRptFilter = vbNullString
On click of the report( created a cmd button)
[CODE]
Code:
Private Sub cmdRptToPDF_Click()
Dim rst As DAO.Recordset
set rst = currentdb.openrecordset("SELECT DISTINCT [cust_id FROM [tblRecon] WHERE ... ORDER BY [cust_id;", dbOpenSnapshot)
do while not rst.eof
strRptFilter = "[cust_id] = " & rst![cust_id]
DoCmd.OutputTo acOutputReport, "rptRecon", acFormatPDF, "C:\Users\slimjen\Desktop\Recon\" & "\" & rst![cust_id] & ".pdf"
doevents
rst.movenext
loop
rst.close
set rst = nothing
End Sub
Please tell me what I am missing?? I tried adding "Public strRptFilter as String" before my Dim statement but to no avail. thanks in advance.