I have one multiselect box called 'listclient.' I have another
multi-select box called 'listemployee.' I found some code that allows
me to query on the listclient box. I'm trying to figure out how to get
my query to query on the listemployee box as well. Thanks in advance
for any help.
Here's my code for querying on the listclient box:
Private Sub cmdRunQuery_Cli ck()
On Error GoTo Err_cmdRunQuery _Click
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String, strWhere As String
Dim i As Integer
Set db = CurrentDb
'*** create the query based on the information on the form
strSQL = "SELECT
datetest1_tbl.f ld_year,datetes t1_tbl.fld_day, datetest1_tbl.f ld_month,datete st1_tbl.fld_bre ak_mins,datetes t1_tbl.fld_brea k_hrs,datetest1 _tbl.fld_date,d atetest1_tbl.fl d_client,datete st1_tbl.fld_pro ject,datetest1_ tbl.fld_subproj ect,datetest1_t bl.fld_currency ,
datetest1_tbl.f ld_duration_hrs ,datetest1_tbl. fld_duration_mi ns,
datetest1_tbl.f ld_note, datetest1_tbl.f ld_rate,
datetest1_tbl.f ld_amount FROM datetest1_tbl "
strWhere = "Where ((datetest1_tbl .fld_date) Between
Forms!aspdash_f orm!date1 And Forms!aspdash_f orm!date2) and
datetest1_tbl.f ld_client IN ("
For i = 0 To listclient.List Count - 1
If listclient.Sele cted(i) Then
strWhere = strWhere & "'" & listclient.Colu mn(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
strSQL = strSQL & strWhere
MsgBox strSQL
'*** delete the previous query
db.QueryDefs.de lete "qryMyQuery "
Set qdf = db.CreateQueryD ef("qryMyQuery" , strSQL)
'*** open the query
'*** DoCmd.OpenQuery "qryMyQuery ", acNormal, acEdit
Exit_cmdRunQuer y_Click:
Exit Sub
Err_cmdRunQuery _Click:
If Err.Number = 3265 Then '*** if the error is the query is
missing
Resume Next '*** then skip the delete line and
resume on the next line
Else
MsgBox Err.Description '*** write out the error and exit
the sub
Resume Exit_cmdRunQuer y_Click
End If
End Sub
multi-select box called 'listemployee.' I found some code that allows
me to query on the listclient box. I'm trying to figure out how to get
my query to query on the listemployee box as well. Thanks in advance
for any help.
Here's my code for querying on the listclient box:
Private Sub cmdRunQuery_Cli ck()
On Error GoTo Err_cmdRunQuery _Click
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String, strWhere As String
Dim i As Integer
Set db = CurrentDb
'*** create the query based on the information on the form
strSQL = "SELECT
datetest1_tbl.f ld_year,datetes t1_tbl.fld_day, datetest1_tbl.f ld_month,datete st1_tbl.fld_bre ak_mins,datetes t1_tbl.fld_brea k_hrs,datetest1 _tbl.fld_date,d atetest1_tbl.fl d_client,datete st1_tbl.fld_pro ject,datetest1_ tbl.fld_subproj ect,datetest1_t bl.fld_currency ,
datetest1_tbl.f ld_duration_hrs ,datetest1_tbl. fld_duration_mi ns,
datetest1_tbl.f ld_note, datetest1_tbl.f ld_rate,
datetest1_tbl.f ld_amount FROM datetest1_tbl "
strWhere = "Where ((datetest1_tbl .fld_date) Between
Forms!aspdash_f orm!date1 And Forms!aspdash_f orm!date2) and
datetest1_tbl.f ld_client IN ("
For i = 0 To listclient.List Count - 1
If listclient.Sele cted(i) Then
strWhere = strWhere & "'" & listclient.Colu mn(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
strSQL = strSQL & strWhere
MsgBox strSQL
'*** delete the previous query
db.QueryDefs.de lete "qryMyQuery "
Set qdf = db.CreateQueryD ef("qryMyQuery" , strSQL)
'*** open the query
'*** DoCmd.OpenQuery "qryMyQuery ", acNormal, acEdit
Exit_cmdRunQuer y_Click:
Exit Sub
Err_cmdRunQuery _Click:
If Err.Number = 3265 Then '*** if the error is the query is
missing
Resume Next '*** then skip the delete line and
resume on the next line
Else
MsgBox Err.Description '*** write out the error and exit
the sub
Resume Exit_cmdRunQuer y_Click
End If
End Sub
Comment