i have a VB form with 4 combo box,
how can i make the combo box to display the contents o a certain coloumn in an access database, and then be able to make a report out of them


I just need to know how to connect my combobox to a feild in a database!

Kindly mention what is the databse you are using and how you are trying to connect the control to the database.

This code is written assuming you are using Oracle and ADO to connect to database.

Dim Con as new ADODB.Connection
Dim Rs As New ADODB.Recordset

Con.ConnectionString = "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=das"
If Con.State = 0 Then
End If

Dim SQLName As String
Rs.Open SQLName, Con, adOpenDynamic, adLockOptimistic
Set CboName.DataSource = Rs
For i = 0 To Rs.RecordCount - 1
CboName.AddItem Rs(0)
Next i

Hope it solves your problem.

Try this sample connection string for Access database.

Con.ConnectionString ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Debasis\Desktop\cypic.mdb;Persist Security Info=False"

how can i display contents of a certain field in a certain table on a combo box

please show me

check out this sample code. this code intends to display all values of "name" field present in a table called "info" from an access database named "demo".

Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase(App.Path & "\demo.mdb")
Set rs = db.OpenRecordset("info", dbOpenTable)
Combo1.AddItem "<Select a Name>"
If rs.RecordCount > 0 Then
    While Not rs.EOF()
        Combo1.AddItem rs!Name
    MsgBox "No data present in the table."
End If
Combo1.ListIndex = 0

here combo1 is the target control which is going to be filled up by the data of said column.

for ur consideration there is a screenshot below.check that out also.
for any more troubles u can meet me at choudhuryshouvik@yahoo.com

Attachments ss.JPG 7.13 KB

how can i display contents of a certain field in a certain table on a combo box

please show me

Please refer to code in post #4 .

This article has been dead for over six months. Start a new discussion instead.