As i'm designing this database I'm realizing there are several different ways to filter data on a form or subform, but I'm wondering if there is some reason why one or the other might be preferred.
My use case:
I need to create a form and/or form subform combo where the data is shown in datasheet view and I can apply filters via combo boxes. The best way I've come across to simply view the data so far is to put the data into a subform that is then added to a blank form that is only used to control the subform. Split Form View may work for this as well, but I'm not sure.
To filter the data I had setup my subform's record source as a query with the criteria being the combo boxes on the main form. I wanted the combo boxes to be able to be used in any combination with each other. That is where I ran into problems. It became difficult for me to write the query logic to support this. This is when I started looking into other ways to filter the data.
Then it seems you can simply use the "combo box wizard" to filter your data. I've had mixed results here.
I came across this method in VBA:
I started working with it then realized there must be a preferred method based on my use case. One that doesn't involve jumping through as many hoops as I think I have been.
With that said, what are you preferred methods for filtering data on forms or subforms via combo boxes?
My use case:
I need to create a form and/or form subform combo where the data is shown in datasheet view and I can apply filters via combo boxes. The best way I've come across to simply view the data so far is to put the data into a subform that is then added to a blank form that is only used to control the subform. Split Form View may work for this as well, but I'm not sure.
To filter the data I had setup my subform's record source as a query with the criteria being the combo boxes on the main form. I wanted the combo boxes to be able to be used in any combination with each other. That is where I ran into problems. It became difficult for me to write the query logic to support this. This is when I started looking into other ways to filter the data.
Then it seems you can simply use the "combo box wizard" to filter your data. I've had mixed results here.
I came across this method in VBA:
Code:
Dim strSQL As String
If IsNull(Me.cboShowSup) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "tblProduct"
Else
strSQL = "SELECT DISTINCTROW tblProduct.* FROM tblProduct " & _
"INNER JOIN tblProductSupplier ON " & _
"tblProduct.ProductID = tblProductSupplier.ProductID " & _
"WHERE tblProductSupplier.SupplierID = " & Me.cboShowSup & ";"
Me.RecordSource = strSQL
End If
I started working with it then realized there must be a preferred method based on my use case. One that doesn't involve jumping through as many hoops as I think I have been.
With that said, what are you preferred methods for filtering data on forms or subforms via combo boxes?