Private Sub Userform_Initialize() Dim strOffice As String Dim i As Long Dim db As DAO.Database Dim rs As DAO.Recordset strOffice = "Test" 'Open the spreadsheet containing the data Set db = OpenDatabase("C:Testdata.xlsx", False, False, "Excel 12.0; IMEX=1;") 'Retrieve the recordset Set rs = db.OpenRecordset("SELECT * FROM `Test`") 'Set the number of Columns = number of Fields in recordset ListBox1.ColumnCount = rs.Fields.Count 'Determine the number of retrieved records With rs .MoveLast i = .RecordCount .MoveFirst End With 'Load the listbox with the retrieved records ListBox1.Column = rs.GetRows(i) 'Cleanup rs.Close db.Close Set rs = Nothing Set db = Nothing lbl_Exit: Exit Sub End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)