Question : Need to count orders in Access report based on condition

I am trying to create a report which totals orders.  Each record is considered an 'order' unless the flag (MultipleOrders) is turned on, meaning that we needed additional records to include all the parts inside the single order.  
In the report I have created the following code (variable rptOrderCount defined earlier in code):
Also, I set rptSameOrder to False initially because I do want to count the order at least once

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
rptOrderCount = rptOrderCount + 1

If Me.MultipleOrder = -1 Then
    If RptSameOrder = True Then rptOrderCount = rptOrderCount - 1
    RptSameOrder = True
    End If

End Sub


This code works if I set the detail section of the report to visible.  However, I do not want the detail information to show.    If I move the code to the format section I get double the counts and I'm not sure why.  
I can provide additional code if necessary.  I'm relatively new writing VBA code for access

Answer : Need to count orders in Access report based on condition

If you are just wanting a grand total of orders then I suggest you do this is in a separate query and just use a Dlookup to get the total.

You will need a 2-level query to get a distinct count...

Select count(*) as MyCount from (Select distinct Orderdatetime from ordersTable)
Random Solutions  
 
programming4us programming4us