S
Steve
Greetings:
I am attempting to modify Allen Browne's Boolean Search Code as follows. A
"where clause" is built by concatenating records in a list box (lbxChosen) to
and added to an SQL statement to define the rowsource of lbxSource. The code
works fine so long as there is only 1 item in lbxChosen. When a second
criteria for the where clause is added, the SQL statement produces no records
(even though I know there are records with both search criteria used).
The code is as follows:
Private Sub cboMeSH_AfterUpdate()
'filter lbxSource based on the MeSH terms in lbxChosen
'determine how many records there are in lbxChosen
intListCount = [lbxChosen].ListCount - 1
'loop through lbxChosen to contruct the where statement
For intLoopCounter = 0 To intListCount
strWhere = strWhere & "Where (tblMesh.chrMeshID = """ &
Me.lbxChosen.Column(0, intLoopCounter) & """) AND "
Next intLoopCounter
'Chop off the trailing " AND "
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at
the end.
strWhere = Left$(strWhere, lngLen)
Debug.Print strWhere
strSQL = "SELECT DISTINCT tblSource.idsSourceID, tblSource.chrTitle " & _
"FROM tblSource INNER JOIN tblMeSH ON tblSource.idsSourceID = "
& _
"tblMeSH.intSourceID " & _
strWhere & ";"
Me.lbxSource.RowSource = strSQL
End If
End Sub
With one criteria debug.print strWhere yields:
Where (tblMesh.chrMeshID = "C14.280.067.248")
- and this works fine
With 2 criteria debug.print strWhere yields:
Where (tblMesh.chrMeshID = "C14.280.067.248") AND Where (tblMesh.chrMeshID =
"C14.240.400")
- this produces no records in lbxSource when I know there should be
I'm having trouble figuring out why the code works for one criteria but not
2 or more? I wonder if it has something to do with the AND statement and
quotations?
Thanks for any help.
I am attempting to modify Allen Browne's Boolean Search Code as follows. A
"where clause" is built by concatenating records in a list box (lbxChosen) to
and added to an SQL statement to define the rowsource of lbxSource. The code
works fine so long as there is only 1 item in lbxChosen. When a second
criteria for the where clause is added, the SQL statement produces no records
(even though I know there are records with both search criteria used).
The code is as follows:
Private Sub cboMeSH_AfterUpdate()
'filter lbxSource based on the MeSH terms in lbxChosen
'determine how many records there are in lbxChosen
intListCount = [lbxChosen].ListCount - 1
'loop through lbxChosen to contruct the where statement
For intLoopCounter = 0 To intListCount
strWhere = strWhere & "Where (tblMesh.chrMeshID = """ &
Me.lbxChosen.Column(0, intLoopCounter) & """) AND "
Next intLoopCounter
'Chop off the trailing " AND "
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at
the end.
strWhere = Left$(strWhere, lngLen)
Debug.Print strWhere
strSQL = "SELECT DISTINCT tblSource.idsSourceID, tblSource.chrTitle " & _
"FROM tblSource INNER JOIN tblMeSH ON tblSource.idsSourceID = "
& _
"tblMeSH.intSourceID " & _
strWhere & ";"
Me.lbxSource.RowSource = strSQL
End If
End Sub
With one criteria debug.print strWhere yields:
Where (tblMesh.chrMeshID = "C14.280.067.248")
- and this works fine
With 2 criteria debug.print strWhere yields:
Where (tblMesh.chrMeshID = "C14.280.067.248") AND Where (tblMesh.chrMeshID =
"C14.240.400")
- this produces no records in lbxSource when I know there should be
I'm having trouble figuring out why the code works for one criteria but not
2 or more? I wonder if it has something to do with the AND statement and
quotations?
Thanks for any help.