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

thanks

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
Con.Open
End If

 
Dim SQLName As String
CboName.Clear
SQLName = "SELECT NAME FROM ENGINEER"
Rs.Open SQLName, Con, adOpenDynamic, adLockOptimistic
Set CboName.DataSource = Rs
For i = 0 To Rs.RecordCount - 1
CboName.AddItem Rs(0)
Rs.MoveNext
Next i
Rs.Close

Hope it solves your problem.

sir Im using Access database

Then you only need to change the connection string.

sir ,
please show me how to do that


thanks

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"

sir
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.Clear
Combo1.AddItem "<Select a Name>"
If rs.RecordCount > 0 Then
    rs.MoveFirst
    While Not rs.EOF()
        Combo1.AddItem rs!Name
        rs.MoveNext
    Wend
Else
    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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.