What's new
  • Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

Visual Basic How to connect ms excel range cells to vb6 combobox?

aljonoime

Enthusiast
Joined
Apr 6, 2014
Messages
141
Reaction
107
Age
29
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.. .
 

matthunter

Enthusiast
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.
 
Comment

matthunter

Enthusiast
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.
 
Comment

Online statistics

Members online
1,092
Guests online
682
Total visitors
1,774

Forum statistics

Threads
813,651
Messages
16,096,761
Members
1,437,006
Top