Don Quixote
New Member
- Joined
- Feb 2, 2025
- Messages
- 6
- Office Version
- 2021
- Platform
- Windows
Hi, I am trying to make an excel userform that connects to an access database. So far I can search and create new database entries from withing excel.
But I can't seem to populate my listbox with a selection of my database table.
Here is my code for initializing the userform and fill the listbox:
If you need more info please ask. I've commented out several lines of code that don't seem to work.
This is my first time working with vba and I've gotten pretty far along for someone with no real coding skills, but right now
I've hit a brick wall.
Any help would be much appreciated.
But I can't seem to populate my listbox with a selection of my database table.
Here is my code for initializing the userform and fill the listbox:
VBA Code:
Private Sub UserForm_Initialize()
Dim con As Object
Dim rs As Object
Set con = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
txtBestelbon.BackColor = RGB(255, 150, 224)
txtTransporteur.BackColor = RGB(255, 150, 224)
txtProduct.BackColor = RGB(255, 150, 224)
txtLosplaats.BackColor = RGB(255, 150, 224)
txtTank.BackColor = RGB(255, 150, 224)
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Dennis\Documents\Blending & Filling\Basis Olie Lossing\Base Oils.accdb;"
con.Open
Set rs.ActiveConnection = con
rs.Open "SELECT [Bestelbon], [Productnaam] FROM [Planning]"
'rs.Open "[Planning]"
'rs.MoveFirst
'ListBox1.RowSourceType = "Table/Query"
'ListBox1.RowSource = rs
'ListBox1.AddItem rs.Fields(3)
'ListBox1.AddItem "SELECT [Bestelbon], [Productnaam] FROM [Planning]"
'ListBox1.AddItem.List(0, 1) = rs![Product naam]
ListBox1.ColumnCount = 2
ListBox1.ColumnWidths = "100;100"
'ListBox1.ListIndex = 1
'ListBox1.ColumnHeads = True
End Sub
If you need more info please ask. I've commented out several lines of code that don't seem to work.
This is my first time working with vba and I've gotten pretty far along for someone with no real coding skills, but right now
I've hit a brick wall.
Any help would be much appreciated.