View Full Version : How do I filter this form?


bozrdang
12-18-2001, 02:52 PM
I have a form with a subform. The main form has Customer, PONumber, and OrderDate fields. The subform contains ProductID, QtyOrdered, QtyProduced, and QtyRemaning fields.

I also have a third form that I want to open and filter when I double click the ProductID field in the subform. I've got the third form to filter by ProductID, but I now realize I need it to filter by BOTH PartNumber and PONumber. The PONumber field is in the main form. How can I do this?

Here is the code I have that filters by the PartNumber:

Private Sub ProductID_DblClick(Cancel As Integer)
On Error GoTo Err_ProductID_DblClick

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmProduction"

stLinkCriteria = "[ProductID]=" & "'" & Me![ProductID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_ProductID_DblClick:
Exit Sub

Err_ProductID_DblClick:
MsgBox Err.Description
Resume Exit_ProductID_DblClick

End Sub

I'm new to code and figured out this much by analyzing the Northwind sample db.

Pat Hartman
12-19-2001, 06:28 PM
stLinkCriteria = "[ProductID]=" & "'" & Me![ProductID] & "' AND [PONumber] = '" & Me.Parent![PONumber] & "'"

The above code assumes that the PONumber is also text. Remove the surrounding single quotes if it is numeric.

bozrdang
12-20-2001, 03:56 PM
Thanks for the reply. I've done what you said, and my code now reads:

stLinkCriteria = "[ProductID]=" & "'" & Me![ProductID] & "'" & "'" And [PONumber] = "'" & "'" & Me.Parent![PONumber] & "'"

Now I get the following error:

"Microsoft Access can't find the field "|" referred to in your expresion."

I have checked all applicable field names in all underlying tables, queries, and forms, and they are all correct. What is "|"? That is not anywhere in my expression. What is causing this?