What's new

Closed How to connect ms excel range cells to vb6 combobox?

Status
Not open for further replies.

aljonoime

Addict
Joined
Apr 6, 2014
Posts
160
Reaction
111
Points
123
Age
32
help naman po sa mga mamaw sa vb6 jan. . .need ko lang po. . panu po kaya yung pag click ko sa combobox magdropdown ung mga values sa cells ng ms excel. . .salamat po sa sasagot.. .
 
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.
 
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.
 
Status
Not open for further replies.

Similar threads

Back
Top