I want to query a Database from Excel Vba (using ADODB) and fill a Combobox with the retrieved List of Values. Unfortunately only the last value of the returned List is displayed in the Dropdown field. I assume that the recordset is a complete String of all returned rows, and so only the last one is visible.
I searched about the topic but only can find info regarding Access, which doesn't seems to help.
This should be the important part of the code, I can provide more if needed:
'-- Create database query
SQLStatement = "SELECT Project_Name FROM ressourceplanning.projects"
'-- Execute query
Recordset.Open SQLStatement, Connection
'-- Write report into combobox (dropdown)
RecordsetArray = Recordset.GetRows
UF_Delete_Project.Cb_DeleteProject.List = RecordsetArray
'UF_Delete_Project.Cb_DeleteProject.RowSourceType = RecordsetArray
The Last line leads to umatching types (error 13) when used. But using "RowSourceType" was the best answer i found so far.
The Recordset contains the correct values so the DB Connection and the query is working per se, its just about the populating of the recordset.
This code here did the trick for me:
RecordsetArray = Recordset.GetRows
For i = LBound(RecordsetArray, 2) To UBound(RecordsetArray, 2)
UF_Delete_Project.Cb_DeleteProject.AddItem RecordsetArray(0, i)
Next i
Thanks to @braX and @FunThomas
.AddItemmethod of the combobox? - braX