0
votes

I have a data entry form which consists of three forms

1- Main form (customer) 2- Sub form (order) 3- Sub form (order details)

the order details sub form is linked to order sub form, also the order sub form is linked to the customer form. I created a report by wizard with customer record set, and then dragged the order records to the report by using "from existing table". Finally, i created a sub report for the order details. From the data entry form, when i click the order sub form record, the corresponding fields of the order details shown only, and that fits my need. Well, I created a command button to print the selected records. I built. The command button has the following code

Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then    'Save any edits.
    Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
    MsgBox "Please select a record"
Else
    strWhere = "[CustomerID] = " & Me.[CustomerID]
    DoCmd.OpenReport "rptcustomers", acViewPreview, , strWhere
End If
End Sub

However, when i select the the second row of the order in the data entry form which is refer to the second order of a customer, the report show all the orders and their details of that customer. I want only the selected order and its details printed. Can any help please. I explained what i did step by step just to be clear to the reader.

2

2 Answers

1
votes

Create New Table then in sub form take a command button and write this code

docmd.runsql "Insert into Table_Name(Fields)values(subform fields name)

then create report from that new Table you Created on Report Closing docmd.runsql delete * from New_Report_Table. done

0
votes

You are filtering by customer (strWhere = "[CustomerID] = " & Me.[CustomerID])

Perhaps you should filter by order:

strWhere = "[OrderID] = " & Me.[OrderID]