0

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

3
Contributors
10
Replies
11
Views
9 Years
Discussion Span
Last Post by debasisdas
0

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

0

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

0

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.

0

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

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

please show me

0

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

Attachments ss.JPG 7.13 KB
0

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 .

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.