troubleshooting Question

Loop in VBA is not looping

Avatar of progismaps
progismapsFlag for United States of America asked on
VBAMicrosoft Access
2 Comments1 Solution408 ViewsLast Modified:
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)

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
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.
Wayne Taylor (webtubbs)

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros