Hi
I've inherited an Access database where there is a form setup which prints out a Job Sheet. This works fine with one record. However I need to set it to loop through several records and print them all out programmaticall y.
This is my code which appears to work fine, but doesn't loop through the records, just prints off the first record however many times there are records to print. This is my code:
[code=vb]
Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strdate As String
Dim strRanger As String
Dim qryName As String
Dim tblName As String
Dim strSQL As String
Dim i As Integer
stDocName = "frmJobSheetTri mble"
tblName = "tblTempJobShee t"
qryName = "qryJobSheetByD ate"
    
strSQL = "delete from tblTempJobSheet "
    
DoCmd.SetWarnin gs False
DoCmd.RunSQL strSQL
    
DoCmd.OpenQuery qryName, acViewNormal ' This creates the temporary table to print the record from.
    
Set db = CurrentDb()
Set rst = db.OpenRecordse t("tbltempJobSh eet")
    
i = 0
MsgBox "You are about to print" & " " & Count & " " & "records.", vbOKCancel
    
DoCmd.OpenForm stDocName, , , , , acWindowNormal
                
rst.MoveFirst
Do While Not rst.EOF
i = i + 1
If rst![SpecificRiskAss] = True Then
DoCmd.PrintOut acPages, 1, 2, , , Yes
                        
End If
                    
If rst![SpecificRiskAss] = False Then
DoCmd.PrintOut acPages, 1, 1, , , Yes
End If
   
rst.MoveNext
Loop
        
rst.close
    
Set rst = Nothing
Set db = Nothing
DoCmd.SetWarnin gs True
DoCmd.close acForm, stDocName
                    
stDocName1 = "frmJobSheetPri nted"
DoCmd.OpenForm stDocName1, , , stLinkCriteria
Exit_cmdOK_Clic k:
Exit Sub
Err_cmdOK_Click :
MsgBox Err.Description
Resume Exit_cmdOK_Clic k
    
End Sub
[/code]
Any help gratefully appreciated.
Thanks
Sandra
					I've inherited an Access database where there is a form setup which prints out a Job Sheet. This works fine with one record. However I need to set it to loop through several records and print them all out programmaticall y.
This is my code which appears to work fine, but doesn't loop through the records, just prints off the first record however many times there are records to print. This is my code:
[code=vb]
Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strdate As String
Dim strRanger As String
Dim qryName As String
Dim tblName As String
Dim strSQL As String
Dim i As Integer
stDocName = "frmJobSheetTri mble"
tblName = "tblTempJobShee t"
qryName = "qryJobSheetByD ate"
strSQL = "delete from tblTempJobSheet "
DoCmd.SetWarnin gs False
DoCmd.RunSQL strSQL
DoCmd.OpenQuery qryName, acViewNormal ' This creates the temporary table to print the record from.
Set db = CurrentDb()
Set rst = db.OpenRecordse t("tbltempJobSh eet")
i = 0
MsgBox "You are about to print" & " " & Count & " " & "records.", vbOKCancel
DoCmd.OpenForm stDocName, , , , , acWindowNormal
rst.MoveFirst
Do While Not rst.EOF
i = i + 1
If rst![SpecificRiskAss] = True Then
DoCmd.PrintOut acPages, 1, 2, , , Yes
End If
If rst![SpecificRiskAss] = False Then
DoCmd.PrintOut acPages, 1, 1, , , Yes
End If
rst.MoveNext
Loop
rst.close
Set rst = Nothing
Set db = Nothing
DoCmd.SetWarnin gs True
DoCmd.close acForm, stDocName
stDocName1 = "frmJobSheetPri nted"
DoCmd.OpenForm stDocName1, , , stLinkCriteria
Exit_cmdOK_Clic k:
Exit Sub
Err_cmdOK_Click :
MsgBox Err.Description
Resume Exit_cmdOK_Clic k
End Sub
[/code]
Any help gratefully appreciated.
Thanks
Sandra
Comment