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
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=C:\test.xls;" & _
"Extended Properties=Excel 8.0;"
'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.ItemData(Combo1.NewIndex) = i
i = i + 1
Set rc = Nothing
Set cn = Nothing
You could also try to check this link, it might be helpful to you, but the solution here in this site is for VB.NET. You could check the logic behind it. You do not have permission to view the full content of this post.Log in or register now.