Question : DoCmd.RunMacro Problem/Question

Hi, I am really new to VB and I have been tasked with modifying an existing Access application to basically print batches of bill of ladings.

I have the print working when I call the report directly like:

DoCmd.OpenReport "Bil OF Lading",, WhereCondition:=sWhere

but there is a macro as part of the original application that does a bunch of other required stuff when a bol prints beyond just printing and I have been trying to run that macro in replace of the DoCmd.OpenReport.

I have tried DoCmd.RunMacro "print_one_bl", WhereCondition:=sWhere but it does not like the WhereCondition clause. Is there any way to accomplish this?

Please see attached for info.

Thanks,

Charlie

Answer : DoCmd.RunMacro Problem/Question

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

Random Solutions  
 
programming4us programming4us