Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATABOUND COMBO BOX

Status
Not open for further replies.

rry2k

Programmer
Jun 28, 2001
678
US
Hi,

Is there a way to make a databound combo box the driver instead of an adodc control? I want to present a list to be selected from then have textboxes updated with there respective field info.

Thanks..Russ
 
with the On_Click event of your combo box set your criteria and query the database.

dim sMyCriteria as string
dim sSQL as string
dim cn as adodb.connection
dim rs as adodb.recordsset


set rs = createobject("adodb.recordset")
set cn = createobject("adodb.connection")

cn.connectionstring = "YourConnectionStringInfo"
cn.open

sMyCriteria = cboCombo.Text
ssql = "SELECT * FROM TABLE WHERE FIELD='" & sMyCriteria & "'"

rs.open sSQL,cn,adOpenDynamic, adlockOptimistic, adCmdText And adExecuteNoRecords
text1.text = rs("Field1")
text2.text = rs("Field2")
text3.text = rs("Field3")
rs.close
set rs = nothing
 
This looks like your right on track but when I try to run this I get an undefined user type on:
dim cn as adodb.connection
 
Go to your project menu, and select references. Then scroll down until you see Microsoft ActiveX data objects 2.x and check it.
 
Sorry to bother you so much with this. I tried 2.0,2.1 and 2.5 and I still get the same error.

Thanks for hanging in there.
 
When you type: "dim cn as" then hit the spacebar, VB intelisense should pop up. Do you see "ADODB" as an option? If you do, select it, then '.' then connection.
 
It's not there. Somehow the reference isn't getting set.
 
And you are sure that you are going to the project menu, selecting references, and checking Microsoft ActiveX data objects 2.x and hitting the OK button?
 
Now that part is working thanks. Now I get a datasource name not found and no driver specified ??
 
you have to set up your connection string so that your VB app can connect to and 'talk' to your database. What kind of database are you going to use(access, oracle,sqlserver)?
 
I'm using access and I'm using a db as a test that I created for another app
 
Do this:

Dim sDatabasePath as string

'where it says TypeYourPathHere, enter the path to
'your database. ie: C:\MyStuff\MyAccess.mdb
cn.connectionstring = "Driver={Microsoft Access Driver (*.mdb)};Dbq=TypeYourPathHere;Uid=Admin;Pwd=;"

cn.open
 
Private Sub DBCombo1_Click(Area As Integer)
Dim sMyCriteria As String
Dim sSQL As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sDatabasePath As String

Set cn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
cn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=f:\db1.mdb;Uid=Admin;Pwd=;"
cn.Open

rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic, adCmdText And adExecuteNoRecords
This is where we are.
command text not set for the command object.
Again I really appreciate your help and patient.
whether we get this or not you will get my vote.

sMyCriteria = DBCombo1.Text
sSQL = "SELECT * FROM EMPLOYEES WHERE FIELD='" & sMyCriteria & "'"


Text1.Text = rs("Name")
Text2.Text = rs("Title")
Text3.Text = rs("Department")
rs.Close
Set rs = Nothing
End Sub

 
looks good. Just replace 'FIELD' in your SQl statement with whatever field you want to search on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top