shuffine@hcreit.com
Registered User.
- Local time
- Today, 17:32
- Joined
- Dec 18, 2013
- Messages
- 19
Access 2007-10
Listbox created: List62 (I know I need to rename it, but for now)
Multi-select: Extended
Row Source Type: Field List
Row Source: qryFieldList
Open Query: qrySelectedFields (I added primary key to first column, just to have at least one destination field).
Goal: to select multiple fields within listbox, click on command button to open query "qrySelectedFields" with selected fields from list box.
This is the code I have on the command_click:
Dim varItem As Variant
Dim strSQL As String
If Me.List62.ItemsSelected.Count = 0 Then
MsgBox "Please select one or more fields.", vbExclamation, "Healthcare REIT"
Me.List62.SetFocus
End If
Exit Sub
For Each varItem In Me.List62.ItemsSelected
strSQL = strSQL & ",[" & varItem & "]"
Next varItem
strSQL = "SELECT" & Mid(strSQL, 3) & " FROM qryFieldList"
CurrentDb.QueryDefs("qrySelectedFields").SQL = strSQL
DoCmd.OpenQuery "qrySelectedFields", acViewNormal, acReadOnly
It does absolutely nothing - doesn't add the fields to "qrySelectedFields", doesn't open the query, notta. Please help! :banghead:
Listbox created: List62 (I know I need to rename it, but for now)
Multi-select: Extended
Row Source Type: Field List
Row Source: qryFieldList
Open Query: qrySelectedFields (I added primary key to first column, just to have at least one destination field).
Goal: to select multiple fields within listbox, click on command button to open query "qrySelectedFields" with selected fields from list box.
This is the code I have on the command_click:
Dim varItem As Variant
Dim strSQL As String
If Me.List62.ItemsSelected.Count = 0 Then
MsgBox "Please select one or more fields.", vbExclamation, "Healthcare REIT"
Me.List62.SetFocus
End If
Exit Sub
For Each varItem In Me.List62.ItemsSelected
strSQL = strSQL & ",[" & varItem & "]"
Next varItem
strSQL = "SELECT" & Mid(strSQL, 3) & " FROM qryFieldList"
CurrentDb.QueryDefs("qrySelectedFields").SQL = strSQL
DoCmd.OpenQuery "qrySelectedFields", acViewNormal, acReadOnly
It does absolutely nothing - doesn't add the fields to "qrySelectedFields", doesn't open the query, notta. Please help! :banghead: