I am trying to split my report into individual files using a specific naming format. I am able to run it correctly for the most part, however, whenever I add current date to the code it won't run anymore. I am getting a Run-Time error '2467'.
Can someone help me find out why my date code is not working??
Can someone help me find out why my date code is not working??
PHP:
Option Compare Database
Private Sub Report_Click()
Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT DISTINCT PIN FROM ExcelImport ORDER BY PIN;", dbOpenSnapshot)
Dim rst As DAO.Recordset
Dim MyPath As String
Dim MyFilename As String
Dim PIN As String
If rs.RecordCount = 0 Then Exit Sub
Do While Not rs.EOF
PIN = rs![PIN]
strRptFilter = "PIN = " & Chr(34) & rs![PIN] & Chr(34)
MyFilename = "RESALL" & "_" & PIN & "_" & Format(Date,"yyyy-mm-dd") & "__" & Format(Date, "yyyy") & "_" & "WAIVER" & ".pdf"
MyPath = "C:\Users\aduong\Desktop\SWTEST\"
DoCmd.OpenReport "Report1", acViewPreview, , "PIN='" & rs!PIN & "'", acHidden
DoCmd.OutputTo acOutputReport, "Report1", acFormatPDF, MyPath & MyFilename
DoCmd.Close acReport, "Report1"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub Report_Close()
strRptFilter = vbNullString
End Sub
Private Sub Report_Open(Cancel As Integer)
If Len(strRptFilter) <> 0 Then
Me.Filter = strRptFilter
Me.FilterOn = True
End If
End Sub