N
Nick 'The Database Guy'
Hello,
I am trying to filter results in a query based on values that I have
selected on a form. The only trouble is that Access does not want to
know, saying that the query is to complex, giving me no results or
telling me that I have a type miss match. The thing is that it works
fine if I just specify one value to filter on, but if I choose
multiple values and insert an OR between them it thinks that I am
specifing a text value and encloses the whole thing in quotes.
Below is the code that I am using to take the items that I have
selected from the list box and put them in a single text box.
' Concatenates all the admission types and puts them in the combo box
that the query is looking at.
Public Function FunctAdmission() As Variant
Dim intLoopVar As Integer
With Forms!frmInpatientAnalysis
If .lstAdmissionTypeSelected.ListCount > 0 Then
FunctAdmission = .lstAdmissionTypeSelected.ItemData(0)
For intLoopVar = 1 To .lstAdmissionTypeSelected.ListCount
- 1
FunctAdmission = FunctAdmission & " Or "
& .lstAdmissionTypeSelected.ItemData(intLoopVar)
Next
End If
End With
End Function
I call it with the statement:
Me.txtAdmissionType = FunctAdmission
And the WHERE statement in the SQL looks like this:
WHERE (((tblRDAdmissionType.AdimssionTypeID)=[Forms]!
[frmInpatientAnalysis]![txtAdmissionType]))
I have also tried calling the function straight from the query, which
works on a single value, but again not on multiple values.
Thank you for reading all this and I hope that you can help, you have
my sincerest thanks in advance.
Nick
I am trying to filter results in a query based on values that I have
selected on a form. The only trouble is that Access does not want to
know, saying that the query is to complex, giving me no results or
telling me that I have a type miss match. The thing is that it works
fine if I just specify one value to filter on, but if I choose
multiple values and insert an OR between them it thinks that I am
specifing a text value and encloses the whole thing in quotes.
Below is the code that I am using to take the items that I have
selected from the list box and put them in a single text box.
' Concatenates all the admission types and puts them in the combo box
that the query is looking at.
Public Function FunctAdmission() As Variant
Dim intLoopVar As Integer
With Forms!frmInpatientAnalysis
If .lstAdmissionTypeSelected.ListCount > 0 Then
FunctAdmission = .lstAdmissionTypeSelected.ItemData(0)
For intLoopVar = 1 To .lstAdmissionTypeSelected.ListCount
- 1
FunctAdmission = FunctAdmission & " Or "
& .lstAdmissionTypeSelected.ItemData(intLoopVar)
Next
End If
End With
End Function
I call it with the statement:
Me.txtAdmissionType = FunctAdmission
And the WHERE statement in the SQL looks like this:
WHERE (((tblRDAdmissionType.AdimssionTypeID)=[Forms]!
[frmInpatientAnalysis]![txtAdmissionType]))
I have also tried calling the function straight from the query, which
works on a single value, but again not on multiple values.
Thank you for reading all this and I hope that you can help, you have
my sincerest thanks in advance.
Nick