M
MaryMalone
I am trying to setup a multi select list box on a form to update a subform on
the same form, but I cant get it to requery. Can you please take a look at
the code I am using and tell me if there is something obviously incorrect? I
took it from someone elses post and then tried to adapt it to my project, but
so far hasnt worked.
Thanks!
Private Sub Command21_Click()
On Error GoTo Err_Command21_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 ProjTable.* FROM ProjTable "
strWhere = "Where CostCenter IN( "
For i = 0 To lstCostCenter.ListCount - 1
If lstCostCenter.Selected(i) Then
strWhere = strWhere & "'" & lstCostCenter.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ");"
strSQL = strSQL & strWhere
'*** delete the previous query
db.QueryDefs.Delete "qryListBox"
Set qdf = db.CreateQueryDef("qryListBox", strSQL)
DoCmd.Requery "subfrmprojchange"
Exit_Command21_Click:
Exit Sub
Err_Command21_Click:
MsgBox Err.Description
Resume Exit_Command21_Click
End Sub
the same form, but I cant get it to requery. Can you please take a look at
the code I am using and tell me if there is something obviously incorrect? I
took it from someone elses post and then tried to adapt it to my project, but
so far hasnt worked.
Thanks!
Private Sub Command21_Click()
On Error GoTo Err_Command21_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 ProjTable.* FROM ProjTable "
strWhere = "Where CostCenter IN( "
For i = 0 To lstCostCenter.ListCount - 1
If lstCostCenter.Selected(i) Then
strWhere = strWhere & "'" & lstCostCenter.Column(0, i) & "', "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ");"
strSQL = strSQL & strWhere
'*** delete the previous query
db.QueryDefs.Delete "qryListBox"
Set qdf = db.CreateQueryDef("qryListBox", strSQL)
DoCmd.Requery "subfrmprojchange"
Exit_Command21_Click:
Exit Sub
Err_Command21_Click:
MsgBox Err.Description
Resume Exit_Command21_Click
End Sub