I work for an insurance company, and the person in the job before me set up an Access form to print 2 reports at the same time (checks and Explanation of Benefit - EOB - forms). If a check is linked to an EOB, Access should first print the check, then the EOB immediately behind it. If the check is not linked, it prints the check and moves to the next one. He wrote some code to print EOB's with their corresponding checks (linked by the field "check_key") as follows:
The problem is that when the first check *not* linked to an EOB prints, it throws off the rest of the batch, and the checks and EOBs print out of order. Can anyone look this over and let me know if they see the problem that's causing this?
Any help is appreciated.
-------
Kyle
Code:
Private Sub Command1_Click()
On Error GoTo Err_Command1_Click
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rsEOB As DAO.Recordset
Dim PauseTime, Start
Set db = CurrentDb
Set rs = db.OpenRecordset("select DISTINCT CHECK_KEY, CHECK_NUMBER from ALYCE_REPORTS_CHECK_PRINTING_QUERY ORDER BY CHECK_NUMBER")
rs.MoveFirst
Do Until rs.EOF
DoCmd.OpenReport "Checks", acViewNormal, , "CHECK_KEY = " & Chr(34) & rs!CHECK_KEY & Chr(34)
Set rsEOB = db.OpenRecordset("select * from ALYCE_REPORTS_EOB_PRINTING_QUERY where CHECK_KEY = " & Chr(34) & rs!CHECK_KEY & Chr(34))
If Not rsEOB.EOF Then
rsEOB.MoveFirst
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
DoCmd.OpenReport "EOB", acViewNormal, , "CHECK_KEY = " & Chr(34) & rs!CHECK_KEY & Chr(34)
End If
If Not rs.EOF Then rs.MoveNext
Loop
rsEOB.Close
Set rsEOB = Nothing
rs.Close
Set rs = Nothing
Set db = Nothing
DoCmd.Close
Exit_Command1_Click:
Exit Sub
Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub
The problem is that when the first check *not* linked to an EOB prints, it throws off the rest of the batch, and the checks and EOBs print out of order. Can anyone look this over and let me know if they see the problem that's causing this?
Any help is appreciated.
-------
Kyle