Load data from access to combo box in vb [Solved/Closed]

sophisticated19 - Aug 19, 2010 at 04:08 AM - Latest reply:  ian_ian
- Jan 19, 2012 at 09:48 PM
Hello,

i'm really desperate for a solution here

can anybody please please tell me how to load data that i've stored in my access database into a combo box?

thank you in advance!


See more 

7 replies

Best answer
dhanakumar(dk) - Aug 27, 2010 at 02:20 AM
11
Thank you
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str As String
Dim I As Integer
con.Open "Provider=sqloledb;Data Source=SSST41;Initial Catalog=sample;User ID=sa;Password=;"
str = "select name from stutable"
rs.Open str, con
i = 0

While Not rs.EOF
Combo1.List(i) = rs.Fields(0)
rs.MoveNext
i = I + 1
Wend

rs.Close

Thank you, dhanakumar(dk) 11

Something to say? Add comment

CCM has helped 1892 users this month

thank you for the code.. it works with my own way of connecting to Access...
rizvisa1 4481 Posts Thursday January 28, 2010Registration dateContributorStatus January 6, 2016 Last seen - Aug 20, 2010 at 09:55 AM
1
Thank you
Where is this combobox ? is it on access form or some thing else
sophisticated19 - Aug 20, 2010 at 10:20 AM
the combo box is in a form created in a vb(2008) project...i have already connected the vb project to the access db. however, now i'm trying to figure out how to retrieve the information i've stored in the access field to the combo box created earlier.

tq!
rizvisa1 4481 Posts Thursday January 28, 2010Registration dateContributorStatus January 6, 2016 Last seen - Aug 20, 2010 at 10:47 AM
It has been some time since I have played with VB. But from what I recall, you could set it record source to a sql statement.
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim I As Integer
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Asm-isntc-asus\database\mast.mdb;Persist Security Info=False"
str = "select Name from mast"
rs.Open str, con
i = 0

While Not rs.EOF
Combo3.List(i) = rs.Fields(0)
rs.MoveNext
i = I + 1
Wend

rs.Close
sophisticated19 - Aug 20, 2010 at 10:19 AM
0
Thank you
the combo box is in a form created in a vb(2008) project...i have already connected the vb project to the access db. however, now i'm trying to figure out how to retrieve the information i've stored in vb to the combo box created earlier.

tq!