We’re trying to loop through a temporary table and get records for printing crystal report forms. It’s working great except for some unknown reason the rst.EOF is processing additional blank forms when it is clearly past the last record. If I only have one set of forms to print, it prints out an extra set of blank form. When I do 2 sets, it prints out an extra set of blank forms. However, when we tested out 6 sets of forms, it printed out four sets of blank forms before it decided that EOF meant EOF. I haven’t seen this happen on my other looping and can’t figure out what to do. Here’s my code:
Private Sub cmdPrint_Packing_List_Click()
On Error GoTo ErrHandler
Dim strPath As String
Dim strPath2 As String
Dim job As Integer
Dim Handle As Integer
Dim moptionx As PEPrintOptions
Dim iResult As Integer
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strCurrPONum As String
Dim strPrevPONum As String
DoCmd.SetWarnings False
‘ this updates the print flag for any records that happen to be in a certain condition
DoCmd.OpenQuery “qupdFlagMIKCOM”
‘this makes a temporary table that is used for the forms
DoCmd.OpenQuery “qmaktmpMIK”
‘this makes a temporary table for the first record to be printed
DoCmd.OpenQuery “qmaktmpMIKPrint”
‘ strPath = “X:form1.rpt”
strPath = “X:form1MIK.rpt”
strPath2 = “X:form2MIK.rpt”
‘ StartDoc (strPath)
moptionx.StructSize = PE_SIZEOF_PRINT_OPTIONS
moptionx.collation = PE_UNCOLLATED
‘the RecCount goes through the first temporary table and if there’s no data, no forms print out
If RecCount = 0 Then
MsgBox “No MIK Labels to print”
Exit Sub
Else
strSQL = “SELECT * FROM [tmpMIK] ORDER BY [PONum]”
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
‘here is where the EOF begins
Do While rst.EOF = False
‘this is the crystal report stuff we need to call in to print the forms
Handle = PEOpenEngine
job = PEOpenPrintJob(strPath)
Handle = PESetPrintOptions(job, moptionx)
Handle = PEOutputToPrinter(job, 1)
Handle = PEStartPrintJob(job, True)
PEClosePrintJob (job)
job = PEOpenPrintJob(strPath2)
Handle = PESetPrintOptions(job, moptionx)
Handle = PEOutputToPrinter(job, 1)
Handle = PEStartPrintJob(job, True)
PEClosePrintJob (job)
PECloseEngine
‘ this updates the print flag, indicating that the form has printed
DoCmd.OpenQuery “qupdFlagMIK”
‘this selects the next record to be printed
DoCmd.OpenQuery “qmaktmpMIKPrint”
rst.MoveNext
Loop
End If
DoCmd.SetWarnings True
ExitHandler:
On Error Resume Next
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
Any suggestions? We’re getting desperate here….