Hi Charlie
Yes, I am on vacation, so sorry if it sometimes takes an extra day to respond. You can ping me if you like on (graham at mandeno dot com).
There seems to be a new concept, DELIV_NUM, introduced here, in addition to BL_NUM. Where does this fit into the picture? Does DELIV_NUM correspond to one delivery - one carrier/trailer and a bunch of BOLs?
Also, do your tables have unique primary keys? I am assuming that BL_NUM is unique in bl_file, but please confirm this.
There are six queries being executed in your macro - "APPEND_TO BL_AUDIT", "APPEND TO HISTORY1", "DELETE FROM BL_FILE TO GO", "APPEND TO BL_FILE TO GO", "mark page with 0" and ""PURGE BL FILE". I'm not sure what these do, nor how important they are to the process, but we'll nevertheless ignore them in the mean time.
That leaves us with printing the reports. This function ought to get you started:
Public Function PrintOneBOL( BL_Num as String) as Boolean
Dim rs as DAO.Recordset
Dim sBL_Filter as String
On Error Goto ProcErr
sBL_Filter = "BL_NUM='" & BL_Num & "'"
Set rs = CurrentDb.OpenRecordset( "Select * from bl_file where " & sBL_Filter )
' Print 1st copy of BOL
DoCmd.OpenReport "Bill OF Lading", acViewNormal, , sBL_Filter
' Print second page if necessary
If rs!MULTI_PAGE Then
DoCmd.OpenReport "BL2", acViewNormal, , sBL_Filter
End If
' Print 2nd copy -- Changed per 3M requirements - 2nd page is identical to 1st except for heading
DoCmd.OpenReport "Bill of Lading - 2nd Copy", acViewNormal, , sBL_Filter
' Print second page if necessary
If rs!MULTI_PAGE Then
DoCmd.OpenReport "BL2", acViewNormal, , sBL_Filter
End If
' Print 3rd copy if shipping point is INTL
If rs!SHIP_PNT = "INTL" Then
DoCmd.OpenReport "Bill OF Lading", acViewNormal, , sBL_Filter
' do you need to print another BL2 here??????
End If
' mark the record as "printed"
With rs
.Edit
!PRINTED = True
.Update
End With
' indicate success
PrintOneBOL = True
ProcEnd:
On Error Resume Next
If Not rs is Nothing then
rs.Close
Set rs = Nothing
End If
Exit Function
ProcErr:
MsgBox "Error printing BOL" & vbCrLf & vbCrLf & "Error #" & Err & ": " & Err.Description
Resume ProcEnd
End Function
I hope there aren't too many typos in there :-)
This function should be in a standard module, not in your form module.
Good luck!
--
Graham