K
kris
I have a subform whose source is a query. The SQL statement for the query is
obtained from the code given below .
Function s()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Forms![ROC-Home1]
Set ctl = frm![control-list]
strSQL = "SELECT Table3.* FROM Table3 WHERE [Controls]="
For Each varItem In ctl.ItemsSelected
If ctl.ItemData(varItem) = "(All)" Then 'added
strSQL = "SELECT Table3.* FROM Table3 OR [Controls]="
Exit For
End If
strSQL = strSQL & "'" & ctl.ItemData(varItem) & "'" & " OR
[Controls]="
Next varItem
'Trim the end of strSQL
strSQL = Left(strSQL, Len(strSQL) - Len(" OR [Controls]="))
strSQL = strSQL & ";"
CurrentDb.QueryDefs("Query3").SQL = strSQL
End Function
I have a button which executes a macro with following actions
• Run code s()
• Sets the visible property of query3 subform to -1;
• Requery
When I change the selection in the list box and run the macro, the query
output should change (that is subform contents should change)but it doesn’t.
The changes are reflected when I close the form and open it again.
I use 2007 MS access and I'm very new to Vb coding.
obtained from the code given below .
Function s()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Forms![ROC-Home1]
Set ctl = frm![control-list]
strSQL = "SELECT Table3.* FROM Table3 WHERE [Controls]="
For Each varItem In ctl.ItemsSelected
If ctl.ItemData(varItem) = "(All)" Then 'added
strSQL = "SELECT Table3.* FROM Table3 OR [Controls]="
Exit For
End If
strSQL = strSQL & "'" & ctl.ItemData(varItem) & "'" & " OR
[Controls]="
Next varItem
'Trim the end of strSQL
strSQL = Left(strSQL, Len(strSQL) - Len(" OR [Controls]="))
strSQL = strSQL & ";"
CurrentDb.QueryDefs("Query3").SQL = strSQL
End Function
I have a button which executes a macro with following actions
• Run code s()
• Sets the visible property of query3 subform to -1;
• Requery
When I change the selection in the list box and run the macro, the query
output should change (that is subform contents should change)but it doesn’t.
The changes are reflected when I close the form and open it again.
I use 2007 MS access and I'm very new to Vb coding.