lonerjohn1078
Registered User.
- Local time
- Today, 11:57
- Joined
- Jan 25, 2019
- Messages
- 19
I have a query form, frmReports2, that I'd like the users to select criteria from to run a report on. The form contains 3 multi-valued fields: ContractType, County, and PriorityCategory.
County and PriorityCategory are stored as multi-valued fields in the table, tblMain. These fields sometimes contain multiple values, as sometimes a contract can cover more than one county and more than one priority category.
If I run the module below with just pform1, pcontrol1, and pfield1, it runs fine without issues.
However, once I add the second (or third) field from which to query from, I get an error message of "The multi-valued field 'County' cannot be used in a WHERE or HAVING clause."
The query criteria is populating properly in the immediate window. But the error pops up on the line calling the report.
I've gotten this module online and adjusted it accordingly to my needs, but I can't seem to figure out how to get around the error.
In the module, the "1" variables are for the ContractType, the "2" variables are for Counties, and the "3" variables are for the PriorityCategory. pform1, pform2, and pform3 are the same value of frmReports2.
Can anyone help me with this? I'm not very strong at Access.
County and PriorityCategory are stored as multi-valued fields in the table, tblMain. These fields sometimes contain multiple values, as sometimes a contract can cover more than one county and more than one priority category.
If I run the module below with just pform1, pcontrol1, and pfield1, it runs fine without issues.
However, once I add the second (or third) field from which to query from, I get an error message of "The multi-valued field 'County' cannot be used in a WHERE or HAVING clause."
The query criteria is populating properly in the immediate window. But the error pops up on the line calling the report.
I've gotten this module online and adjusted it accordingly to my needs, but I can't seem to figure out how to get around the error.
In the module, the "1" variables are for the ContractType, the "2" variables are for Counties, and the "3" variables are for the PriorityCategory. pform1, pform2, and pform3 are the same value of frmReports2.
Can anyone help me with this? I'm not very strong at Access.
Code:
Function MultipleContractsCriteria(pform1 As Form, pcontrol1 As ListBox, pfield1 As String, pform2 As Form, pcontrol2 As ListBox, pfield2 As String, pform3 As Form, pcontrol3 As ListBox, pfield3 As String)
Dim var1 As Variant
Dim var2 As Variant
Dim var3 As Variant
Dim strcriteria As String
Dim strcriteria1 As String
Dim strcriteria2 As String
Dim strcriteria3 As String
For Each var1 In pcontrol1.ItemsSelected
strcriteria1 = strcriteria1 & pfield1 & " = '" & pcontrol1.ItemData(var1) & "' or "
Next var1
For Each var2 In pcontrol2.ItemsSelected
strcriteria2 = strcriteria2 & pfield2 & " = '" & pcontrol2.ItemData(var2) & "' or "
Next var2
For Each var3 In pcontrol3.ItemsSelected
strcriteria3 = strcriteria3 & pfield3 & " = '" & pcontrol3.ItemData(var3) & "' or "
Next var3
strcriteria = Left(strcriteria1, Len(strcriteria1) - 4) & " and " & Left(strcriteria2, Len(strcriteria2) - 4) & " and " & Left(strcriteria3, Len(strcriteria3) - 4)
Debug.Print strcriteria
DoCmd.OpenReport pform1.Name, acViewPreview, , strcriteria
Set pform = Nothing
Set pcontrol = Nothing
End Function