I have been searching for a VBA that will go through a recordset and print different reports based a text value per record.
here is my current code, and it is giving me an error Loop with out Do. This code is attached to command button. I am using access 2016. Any help to get this to work is greatly appreciated.
here is my current code, and it is giving me an error Loop with out Do. This code is attached to command button. I am using access 2016. Any help to get this to work is greatly appreciated.
Code:
Private Sub Printforms_Click()
Dim rst As Recordset
Dim db As Database
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblforForms")
If Not (rst.EOF And rst.BOF) Then
rst.MoveLast
rst.MoveFirst
End If
Do While Not rst.EOF = True
If phone.Value = "Y" And powercord.Value = "Y" Then
DoCmd.OpenReport "rptgtg", acViewNormal
DoCmd.Close acReport, "rptgreen"
Else
If phone.Value = "N" And powercord.Value = "N" Then
DoCmd.OpenReport "rptphoneerror", acViewNormal
DoCmd.Close acReport, "rptred"
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Last edited by a moderator: