First off, sorry if this gets too verbose or wordy.
I have a form that contains several combo boxes for the user to select info from, that then goes out as the criteria for a query and the report associated with it. All of this was working fine, until one of the users decided that there is one combo box that they wish to select more then one field from.
I have already switched that combo box to a list box and after reading other forum threads on this topic, I did a test form, dropped in the following VBA code and had limited success.
Here is the code I used.
Private Sub cmdTest_Click()
Dim DB As Database
Dim QDF As QueryDef
Dim varRow As Variant
Dim strCriteria As String
Dim strSQL As String
Set DB = CurrentDb()
Set QDF = DB.QueryDefs("qryExpense"
strCriteria = ""
For Each varRow In cboService.ItemsSelected
If strCriteria = "" Then
strCriteria = "frmreport.cboservice In ('" & Me!cboService.Column(0, varRow) & "'"
Else
strCriteria = strCriteria & ", '" & Me!cboService.Column(0, varRow) & "'"
End If
Next varRow
strCriteria = strCriteria & "
"
strSQL = "SELECT * FROM [Invoice Table] WHERE [Invoice Table].[Service Code] IN(" & strCriteria & "
;"
QDF.SQL = strSQL
DoCmd.OpenQuery "qryExpense"
Set DB = Nothing
Set QDF = Nothing
End Sub
The string (strCriteria) gets populated correctly, but when the query fires up, it is still wanting a parameter value for frmReport.cboService
Once I figure that part out, can I still combine a list box with multiple combo boxes on the same form??? Currently I am using SQL for the logic, but am not against going to VBA. using SQL I already have a WHERE statement that is several lines long. Recreating that in VBA is not the first thing I would want to do if I did not have to.
Many thanks in advance for helping me work through this problem
T
I have a form that contains several combo boxes for the user to select info from, that then goes out as the criteria for a query and the report associated with it. All of this was working fine, until one of the users decided that there is one combo box that they wish to select more then one field from.
I have already switched that combo box to a list box and after reading other forum threads on this topic, I did a test form, dropped in the following VBA code and had limited success.
Here is the code I used.
Private Sub cmdTest_Click()
Dim DB As Database
Dim QDF As QueryDef
Dim varRow As Variant
Dim strCriteria As String
Dim strSQL As String
Set DB = CurrentDb()
Set QDF = DB.QueryDefs("qryExpense"
strCriteria = ""
For Each varRow In cboService.ItemsSelected
If strCriteria = "" Then
strCriteria = "frmreport.cboservice In ('" & Me!cboService.Column(0, varRow) & "'"
Else
strCriteria = strCriteria & ", '" & Me!cboService.Column(0, varRow) & "'"
End If
Next varRow
strCriteria = strCriteria & "
strSQL = "SELECT * FROM [Invoice Table] WHERE [Invoice Table].[Service Code] IN(" & strCriteria & "
QDF.SQL = strSQL
DoCmd.OpenQuery "qryExpense"
Set DB = Nothing
Set QDF = Nothing
End Sub
The string (strCriteria) gets populated correctly, but when the query fires up, it is still wanting a parameter value for frmReport.cboService
Once I figure that part out, can I still combine a list box with multiple combo boxes on the same form??? Currently I am using SQL for the logic, but am not against going to VBA. using SQL I already have a WHERE statement that is several lines long. Recreating that in VBA is not the first thing I would want to do if I did not have to.
Many thanks in advance for helping me work through this problem
T