My earlier reply was done when I was in a rush, getting ready to leave for work. It's not quite right.
In the Case selectors, where you have things like "orders.id_order", you should instead have the name of a
field in the form's recordset.
Thus, your first 4 cases should look something like this:
Code:
Case 1
stLinkCriteria = ""
Case 2
stLinkCriteria = "id_order = " & txtID
Case 3
stLinkCriteria = "supplier = '" & txtSupplier & "'"
Case 4
stLinkCriteria = "employee = '" & employ & "'"
Here I'm assuming "id_order", "supplier", and "employee" are the names of fields in the main form's recordset, and "txtID", "txtSupplier", and "employ" are names of text box or combo box controls on your filter form. I notice you removed the ' characters in case 2, so I guess you realize that you should omit them for numeric fields. That left case 2 with
& "" at the end, which has no effect, so I deleted that.
To test for an empty field, you test whether it IS NULL, so the 5th case is like this:
Code:
Case 5
stLinkCriteria = "commitment_date IS NULL"
Now that you've told me the 6th and 7th cases are on a subform, I need to ask a question. When, for example, case 6 is chosen, do you mean to show
all orders on the main form, but only show on the subform the order details that have no invoice date, or do you mean to show on the main form only orders where
none of the details have an invoice date? A similar question applies to case 7.
If you want to show
all orders, but only show details that have no invoice date, then case 6 means we need two filters, one for the main form and one for the subform. Each case, including cases 1-5, will set one of the filters to a criteria string, but set the other filter to "". For example:
Code:
Case 1
strMainFilter = ""
strSubFilter = ""
Case 2
strMainFilter = "id_order = " & txtID
strSubFilter = ""
...
Case 6
strMainFilter = ""
strSubFilter = "invoice_date IS NULL"
Case 7
strMainFilter = ""
strSubFilter = "payment_date IS NULL"
Assuming the name of the subform
control (not the subform itself) is "order_details_subform", you set the form and subform filters like this:
Code:
With Forms(stDocName)
.Filter = strMainFilter
.FilterOn = Len(strMainFilter) > 0
!order_details_subform.Form.Filter = strSubFilter
!order_details_subform.Form.FilterOn = Len(strSubFilter) > 0
End With
On the other hand, if you only want to show orders where
none of the details have an invoice date, we only need to filter the main form--but we'll have to figure out, in its filter criteria, whether it has any details with an invoice date. This is a little bit complex, but I think it should work:
Code:
Case 6
stLinkCriteria = "DCount(""invoice_date"", ""order_details"", ""id_order = " & id_order & """) = 0"
Case 7
stLinkCriteria = "DCount(""payment_date"", ""order_details"", ""id_order = " & id_order & """) = 0"
There is another way to accomplish this latter version, but it requires adding a pair of columns to the form's recordset (its Record Source query). In the query design grid, you would add these columns:
Invoiced: DCount("invoice_date", "order_details", "id_order = " & id_order) = 0
Paid: DCount("payment_date", "order_details", "id_order = " & id_order) = 0
Then cases 6 and 7 would become:
Code:
Case 6
stLinkCriteria = "Invoiced = False"
Case 7
stLinkCriteria = "Paid = False"
This is a little easier to understand. Unfortunately, it will make the form's source query slower, because for each order it has to scan the order_details table twice, once to see if any details have been invoiced and once to see if any have been paid. Rick Sprague
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein