![]() |
|
|
|
#1
|
||||
|
||||
|
There's a thread at http://answers.microsoft.com/en-us/o...6-8db862b6032c which demonstrates how to read an Access table into a list box, and a similar code example for Excel on my web site at http://www.gmayor.com/Userform_ComboBox.html
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#2
|
|||
|
|||
|
Quote:
Quote:
Quote:
I'm ashamed to admit that I went through all three of your replies in exhaustive detail but I still don't seem to be getting it. For now I am just trying to use Excel as the data source. I tried to create a simple form with one list box control and a named range in excel with four values in the column. ![]() ![]() Code:
Sub InitializeDocument()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
' Open the database
'Set db = OpenDatabase("C:\Temp\ItemSheet.xlsx", False, False, "Excel 12.0")
Set db = OpenDatabase("C:\Temp\ItemSheet.xlsx", False, False, "Excel 12.0; IMEX=1;")
' Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM ItemRange")
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
' Set the number of Columns = number of Fields in recordset
ListBox1.ColumnCount = rs.Fields.Count
' Load the ListBox with the retrieved records
ListBox1.Column = rs.GetRows(NoOfRecords)
' Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
Sorry for the never ending newbie questions.
|
|
| Thread Tools | |
| Display Modes | |
|
|