R
R50YEE
I hope somebody can help me.
I have created a dialog box (form) which has several mutiselect list boxes,
these boxes, using the code procedure below, load strings into separate text
boxes which shows the user what they have selected. These text boxes are then
used as inputs for a parameter query. The code works fine and returns the
correct values in the textboxes ie "Xvalue" OR "Yvalue" and the dates are
shown as #date#
I used the normal Forms!Mydialogform!Mytextbox as a parameter in the
criteria box of the query. I use a separate command button on the dialog box
form to run the code
Only problem is when I run the query it returns nil values.
Private Sub Command116_Click()
'******************** Code3 Start ************************
Dim db As DAO.Database
Dim varItem As Variant
Dim strSQL1 As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strSQL5 As String
Dim strSQL6 As String
Set db = CurrentDb()
Set Contols1 = Me!ModelFilter
Set Contols2 = Me!FirstDateFilter
Set Contols3 = Me!SecondDateFilter
Set Contols4 = Me!OrderCountryFilter
Set Contols5 = Me!SteeringHandFilter
Set Contols6 = Me!GearboxTypeFilter
strSQL1 = ""
strSQL2 = ""
strSQL3 = ""
strSQL4 = ""
strSQL5 = ""
strSQL6 = ""
'enumerate selected items and
'concatenate to strSQL
For Each varItem In Contols1.ItemsSelected
strSQL1 = strSQL1 & Chr(34) & Contols1.ItemData(varItem) & Chr(34) &
" Or "
Next varItem
For Each varItem In Contols2.ItemsSelected
strSQL2 = strSQL2 & Contols2.ItemData(varItem) & """"
Next varItem
For Each varItem In Contols3.ItemsSelected
strSQL3 = strSQL3 & Contols3.ItemData(varItem) & """"
Next varItem
For Each varItem In Contols4.ItemsSelected
strSQL4 = strSQL4 & Chr(34) & Contols4.ItemData(varItem) & Chr(34) &
" Or "
Next varItem
For Each varItem In Contols5.ItemsSelected
strSQL5 = strSQL5 & Chr(34) & Contols5.ItemData(varItem) & Chr(34) &
" Or "
Next varItem
For Each varItem In Contols6.ItemsSelected
strSQL6 = strSQL6 & Chr(34) & Contols6.ItemData(varItem) & Chr(34) &
" Or "
Next varItem
'Trim the end of strSQL
strSQL1 = Left(strSQL1, Len(strSQL1) - 3)
strSQL2 = Left(strSQL2, Len(strSQL2) - 1)
strSQL3 = Left(strSQL3, Len(strSQL3) - 1)
strSQL4 = Left(strSQL4, Len(strSQL4) - 3)
strSQL5 = Left(strSQL5, Len(strSQL5) - 3)
strSQL6 = Left(strSQL6, Len(strSQL6) - 3)
Me!TbModelQryParm = strSQL1
Me!TbFirstDateQryParm = strSQL2
Me!TbSecondDateQryParm = strSQL3
Me!TbOrderCountryQryParm = strSQL4
Me!TbSteeringHandQryParm = strSQL5
Me!TbGearBoxTypeQryParm = strSQL6
DoCmd.OpenQuery "Result_query"
Set db = Nothing
'******************** Code3 end ************************
End Sub
I have created a dialog box (form) which has several mutiselect list boxes,
these boxes, using the code procedure below, load strings into separate text
boxes which shows the user what they have selected. These text boxes are then
used as inputs for a parameter query. The code works fine and returns the
correct values in the textboxes ie "Xvalue" OR "Yvalue" and the dates are
shown as #date#
I used the normal Forms!Mydialogform!Mytextbox as a parameter in the
criteria box of the query. I use a separate command button on the dialog box
form to run the code
Only problem is when I run the query it returns nil values.
Private Sub Command116_Click()
'******************** Code3 Start ************************
Dim db As DAO.Database
Dim varItem As Variant
Dim strSQL1 As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strSQL5 As String
Dim strSQL6 As String
Set db = CurrentDb()
Set Contols1 = Me!ModelFilter
Set Contols2 = Me!FirstDateFilter
Set Contols3 = Me!SecondDateFilter
Set Contols4 = Me!OrderCountryFilter
Set Contols5 = Me!SteeringHandFilter
Set Contols6 = Me!GearboxTypeFilter
strSQL1 = ""
strSQL2 = ""
strSQL3 = ""
strSQL4 = ""
strSQL5 = ""
strSQL6 = ""
'enumerate selected items and
'concatenate to strSQL
For Each varItem In Contols1.ItemsSelected
strSQL1 = strSQL1 & Chr(34) & Contols1.ItemData(varItem) & Chr(34) &
" Or "
Next varItem
For Each varItem In Contols2.ItemsSelected
strSQL2 = strSQL2 & Contols2.ItemData(varItem) & """"
Next varItem
For Each varItem In Contols3.ItemsSelected
strSQL3 = strSQL3 & Contols3.ItemData(varItem) & """"
Next varItem
For Each varItem In Contols4.ItemsSelected
strSQL4 = strSQL4 & Chr(34) & Contols4.ItemData(varItem) & Chr(34) &
" Or "
Next varItem
For Each varItem In Contols5.ItemsSelected
strSQL5 = strSQL5 & Chr(34) & Contols5.ItemData(varItem) & Chr(34) &
" Or "
Next varItem
For Each varItem In Contols6.ItemsSelected
strSQL6 = strSQL6 & Chr(34) & Contols6.ItemData(varItem) & Chr(34) &
" Or "
Next varItem
'Trim the end of strSQL
strSQL1 = Left(strSQL1, Len(strSQL1) - 3)
strSQL2 = Left(strSQL2, Len(strSQL2) - 1)
strSQL3 = Left(strSQL3, Len(strSQL3) - 1)
strSQL4 = Left(strSQL4, Len(strSQL4) - 3)
strSQL5 = Left(strSQL5, Len(strSQL5) - 3)
strSQL6 = Left(strSQL6, Len(strSQL6) - 3)
Me!TbModelQryParm = strSQL1
Me!TbFirstDateQryParm = strSQL2
Me!TbSecondDateQryParm = strSQL3
Me!TbOrderCountryQryParm = strSQL4
Me!TbSteeringHandQryParm = strSQL5
Me!TbGearBoxTypeQryParm = strSQL6
DoCmd.OpenQuery "Result_query"
Set db = Nothing
'******************** Code3 end ************************
End Sub