first of all, apologies. I am a relatively new VBA user, and I am a bit lost in the search for the answer to the question below.
I am creating a UserForm which will include some ComboBox to get user's input to query data. I would like the possible values of these ComboBoxes to be "pulled" from the DataModel of the workbook, where I loaded (as Connection Only) the Excel file containing the possible options. Such excel is organized by columns (one column per ComboBox I'll need to use), where each row is a possible value for the comboBox.
I would strongly prefer to load the file as connection only (rather than creating a PivotTable in one of the Workbook sheets).
I believe that, if I were able to "extract" from the columns in the DataModel the various values in each column, I could use the Add.Item method of the ComboBox.
The issue I am having: I cannot retrieve the values of the columns in the Power Pivot Data Model.
The data in the Power Pivot is organized as such:
Table name: src_FieldOptions Column1: Door Options (possible values in rows: Electric, Pneumatic, Manual) Column2: Finishing (Painted, Glossy, Matte)
I tried to use the code using the DataModel Object (see below), but I can't find a way to retrieve the column values (for each row), even if I am able to identify the columns.
Any help you can give? Thanks a lot
Sub Find_Values()
Dim conn As WorkbookConnection
Dim model_Table As modelTable
Dim model_Column As ModelTableColumn
' Set the connection to the Power Pivot Data Model
Set conn = ThisWorkbook.Connections("Query - src_FieldOptions")
For Each model_Table In conn.ModelTables
Debug.Print "Table Name: " & model_Table.Name. '<--this is working as expected
For Each model_Column In model_Table.ModelTableColumns
Debug.Print "Column Header: " & model_Column.Name & "; " & model_Column.DataType '<-- working as expected
' QUESTION FOR YOU ALL: what code should I use here to retrieve the values in the rows of the Data model?
Next model_Column
Next model_Table
End Sub
ModelTableobject for retrieving data inObject Browser.ADOConnection.Microsoft documentation:
Update:
Microsoft.ACE.OLEDB.12.0.name