Can anyone lend a hand and help me figure out why my VBA script is quitting in the middle of a script?
Code:
Sub Test
Dim rst As DAO.RecordsetDim strReport As String
Dim rptSavePath As String
Dim EmailAddress As String
Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT [ClientID] FROM [tblPettyCashTransactions] ORDER BY [ClientID];", dbOpenSnapshot)
strReport = "rptPettyCash"
rptSavePath = "C:\rptsave\"
If Dir(rptSavePath) = Null Then
MkDir rptSavePath
End If
rptSavePath = rptSavePath & rst![ClientID] & " PettyCash.pdf"
Do While Not rst.EOF
rptSavePath = "C:\rptsave\" & rst![ClientID] & " PettyCash.pdf"
If Not Dir(rptSavePath) = "" Then
Kill (rptSavePath)
End If
strRptFilter = "[ClientID] = " & rst![ClientID]
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, rptSavePath ' Completes this action successfully but never moves on.
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
I've marked where the sub just quits. There are no message boxes and nothing seems to go wrong, everything works great so far.