Avatar of progismaps
progismaps
Flag for United States of America

asked on 

Loop in VBA is not looping

In Access 2013, I'm trying to create a loop in VBA code that opens a table and creates a report based on records within the table.  I've tried several different methods, but the loop returns the same values for the first record.  Here is the code:

Dim rs As DAO.Recordset
Dim strFileName As String
Dim db As Database
Dim strPathAndFile As String
Dim strClient As String
Dim strReport As String
Dim strProject As String

Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset("tblInvoices-GroupClients", dbOpenTable)

rs.MoveFirst
If rs.RecordCount <> 0 Then
  MsgBox rs.RecordCount
  Do Until rs.EOF
      strClient = DLookup("Client", "tblInvoices-GroupClients")
      strProject = DLookup("Project", "tblInvoices-GroupClients")
      MsgBox strClient & " " & strProject
      Rem strReport = "rptInvoicesMonthly"
      Rem DoCmd.OpenReport strReport, acViewReport, , "CLIENT = '" & strClient & "' And Project = '" & strProject & "'"
      Rem DoCmd.OutputTo acOutputReport, strReport, "PDFFormat(*.pdf)", "", True, acExportQualityScreen
      Rem DoCmd.Close acReport, strReport, acSaveNo
       rs.MoveNext
  Loop
  rs.Close
End If

The MsgBox's show the correct values for the first record, but when it loops to the next record it shows the same vales.
VBAMicrosoft Access

Avatar of undefined
Last Comment
progismaps

8/22/2022 - Mon