Hey Gang - need some help...
I am working on setting up a form that will allow "power users" in one of my applications to create their own queries "on-the-fly" by selecting tables and subsequent fields from two listboxes. I am having issues building the criteria for my "fields" listbox as the criteria in the loop is erroring. Heres the setup:
3 tables many-to-many relationship between 'tblTables' and 'tblFields' based on a junction table, 'tblTablesFieldsJNX' The list box for the 'Fields' selection is based off of a query and has 3 columns:
- objTableName
- objFieldName
- objFieldAlias
in the fields listbox the first two columns are hidden and only the alias field is displayed. In the 'On_Click' event of the list box I have the following code:
Basically, the list box is set to multi-select and as the user selects/unselects items in the listbox I want to generate a string that shows the table name and the field name as displayed in SQL for queries. The problem I am running into is that when I use" Me.lstFields.Column(0) & "." & Me.lstFields.Column(1)" to build the string it changes each selection...
i.e. I click 3 different fields in the listbox but the string ends up replicating the same field name and table name 3 times like:
dbo_BAS_TABLEA.FieldA, dbo_BAS_TABLEA.FieldA, dbo_BAS_TABLEA.FieldA,
instead of what it should like:
dbo_BAS_TABLEA.FieldA, dbo_BAS_TABLEB, FieldX, dbo_BAS_TABLEC, FieldZ, etc....
any thoughts?
Thanks in Advance,
Kev
I am working on setting up a form that will allow "power users" in one of my applications to create their own queries "on-the-fly" by selecting tables and subsequent fields from two listboxes. I am having issues building the criteria for my "fields" listbox as the criteria in the loop is erroring. Heres the setup:
3 tables many-to-many relationship between 'tblTables' and 'tblFields' based on a junction table, 'tblTablesFieldsJNX' The list box for the 'Fields' selection is based off of a query and has 3 columns:
- objTableName
- objFieldName
- objFieldAlias
in the fields listbox the first two columns are hidden and only the alias field is displayed. In the 'On_Click' event of the list box I have the following code:
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
' Build a list of the selections.
Set ctl = Me.lstFields
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Me.lstFields.Column(0) & "." & Me.lstFields.Column(1)
Else
Criteria = Criteria & ", " & Me.lstFields.Column(0) & "." & Me.lstFields.Column(1)
End If
Next Itm
Me.txtFields = Criteria
Basically, the list box is set to multi-select and as the user selects/unselects items in the listbox I want to generate a string that shows the table name and the field name as displayed in SQL for queries. The problem I am running into is that when I use" Me.lstFields.Column(0) & "." & Me.lstFields.Column(1)" to build the string it changes each selection...
i.e. I click 3 different fields in the listbox but the string ends up replicating the same field name and table name 3 times like:
dbo_BAS_TABLEA.FieldA, dbo_BAS_TABLEA.FieldA, dbo_BAS_TABLEA.FieldA,
instead of what it should like:
dbo_BAS_TABLEA.FieldA, dbo_BAS_TABLEB, FieldX, dbo_BAS_TABLEC, FieldZ, etc....
any thoughts?
Thanks in Advance,
Kev
Last edited: