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

- - 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 

3 replies

Best answer
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

Say "Thank you" 11

A few words of thanks would be greatly appreciated. Add comment

CCM 4570 users have said thank you to us this month

thank you for the code.. it works with my own way of connecting to Access...
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
915
1
Thank you
Where is this combobox ? is it on access form or some thing else
-
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
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
915 -
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
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!