Option Explicit 'Forces you to declare all your variables
Dim cn As ADODB.Connection
Dim rc As ADODB.Recordset
Dim strSQL As String
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rc = New ADODB.Recordset
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=C:\test.xls;" & _
"Extended Properties=Excel 8.0;"
.Open
End With
'Compose your SQL string
strSQL = "SELECT * FROM [Sheet1$]" 'This is... if you don't rename your sheets
rc.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, 1
Dim i As Integer
Dim cnt As Integer
cnt = rc.RecordCount
i = 0
Do While rc.EOF = False
Combo1.AddItem (rc(0).Value)
Combo1.ItemData(Combo1.NewIndex) = i
i = i + 1
rc.MoveNext
Loop
rc.Close
cn.Close
Set rc = Nothing
Set cn = Nothing
End Sub
Credits to the author @
You do not have permission to view the full content of this post.
Log in or register now.