R
Rana
Hello again,
I'm trying to create a query that uses a multi select list box to set the
criteria which is then used to look up values from a table. I have written
VBA code (with lots of appreciated help from this discussion group) for
comparing the selected criteria to one field however I want it to compare the
selection to two fields. To make things clearer, I want to compare selected
skills/interests to two fields that contain these "skills/interests",
Skills/Interests Preference 1 and Skills/Interests Preference 2.
Here is my code:
'***********************************************************
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim i As Integer
Dim strSQL As String
Dim strIN As String
Dim strWhere As String
Set db = CurrentDb
strSQL = "SELECT
Skills_Interests.ROTAID,Skills_Interests.Skills_Interests_Preference1 FROM
Skills_Interests "
For i = 0 To lstSkillsInterests.ListCount - 1
If lstSkillsInterests.Selected(i) Then
strIN = strIN & "'" & lstSkillsInterests.Column(0, i) & "', "
End If
Next i
strWhere = "Where Skills_Interests.Skills_Interests_Preference1 IN( " &
Left(strIN, Len(strIN) - 1) & ")"
strSQL = strSQL & strWhere
'MsgBox strSQL
'*** delete the previous query
db.QueryDefs.Delete "SIP1"
Set qdf = db.CreateQueryDef("SIP1", strSQL)
'***********************************************************
I've tried writing out the same bit of code and creating another query,
SIP2, that compares the selection directly to the second field however when I
run the "Mother query" that collates all the info. I only get records that
contain my selection in both fields. Can I do something to the VBA code or is
it something to do with the "Mother query"? I'm not sure how clear this is
but any help would be grately appreciated.
Regards,
Rana.
I'm trying to create a query that uses a multi select list box to set the
criteria which is then used to look up values from a table. I have written
VBA code (with lots of appreciated help from this discussion group) for
comparing the selected criteria to one field however I want it to compare the
selection to two fields. To make things clearer, I want to compare selected
skills/interests to two fields that contain these "skills/interests",
Skills/Interests Preference 1 and Skills/Interests Preference 2.
Here is my code:
'***********************************************************
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim i As Integer
Dim strSQL As String
Dim strIN As String
Dim strWhere As String
Set db = CurrentDb
strSQL = "SELECT
Skills_Interests.ROTAID,Skills_Interests.Skills_Interests_Preference1 FROM
Skills_Interests "
For i = 0 To lstSkillsInterests.ListCount - 1
If lstSkillsInterests.Selected(i) Then
strIN = strIN & "'" & lstSkillsInterests.Column(0, i) & "', "
End If
Next i
strWhere = "Where Skills_Interests.Skills_Interests_Preference1 IN( " &
Left(strIN, Len(strIN) - 1) & ")"
strSQL = strSQL & strWhere
'MsgBox strSQL
'*** delete the previous query
db.QueryDefs.Delete "SIP1"
Set qdf = db.CreateQueryDef("SIP1", strSQL)
'***********************************************************
I've tried writing out the same bit of code and creating another query,
SIP2, that compares the selection directly to the second field however when I
run the "Mother query" that collates all the info. I only get records that
contain my selection in both fields. Can I do something to the VBA code or is
it something to do with the "Mother query"? I'm not sure how clear this is
but any help would be grately appreciated.
Regards,
Rana.