There is some literature in the expert exchange and teck Republic on using the combobox.recordset property to fill in combobox in the Access form.
These controls are usually populated with the string "SELECT *" in the rowsource properties of the control, referencing the table or query available on the client side of the application. When I need to display server-side data in combobox, I create a temporary local table and import the requested records. This takes a lot of time, especially with large tables.
The ability to use a recordset to populate a combobox control will allow the user to directly display server-side data.
Inspired by the two previous examples, I wrote the code as follows:
Dim rsPersonne as ADODB.recordset Set rsPersonne = New ADODB.Recordset Set rsPersonne.ActiveConnection = connexionActive rsPersonne.CursorType = adOpenDynamic rsPersonne.LockType = adLockPessimistic rsPersonne.CursorLocation = adUseClient rsPersonne.Open "SELECT id_Personne, nomPersonne FROM Tbl_Personne" fc().Controls("id_Personne").Recordset = rsPersonne
Where:
- connexionActive: my persistent ADO connection to my database server
- fc (): my current / active form
- controls ("id_Personne"): this is a combobox control to populate the list of company employees
- Access Version 2003
Unfortunately this will not work!
In debug mode, I can verify that the recordset is correctly created, with the requested columns and data, and is correctly connected to the combobox control. Unfortunately, when I show the form, I get an empty combo box, no entries! Any help is appreciated.
EDIT:
This record set property is indeed available for a specific combobox, not a standard control, and I was very surprised to find it a few days ago. I have already tried to use the combobox callback function or populate the list using the "addItem" method for combobox. All this takes a lot of time.
vba ms-access combobox adodb recordset
Philippe grondier
source share