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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code won't populate DataCombo

Status
Not open for further replies.

billybobk

Programmer
Oct 14, 2002
130
0
0
US
Can anyone see why this code won't populate a DataCombo? p.s. I can't use an adodc with this app. (The connect string is good for dsn-less dBase IV datasources)
--------------------------------------------

Private Sub Form_Load()
Dim strQuery As String
Dim rs As ADODB.Recordset
Dim conn As ADODB.Connection

Set conn = New ADODB.Connection
With conn
.CursorLocation = adUseClient
.ConnectionString= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & ";Extended Properties=dBASE IV;User ID=Admin;Password=" 'this is actually on one line!
.Open
End With

strQuery = "Select Name from Users"

Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = conn
.CursorType = adOpenStatic
.Source = strQuery
.Open
End With

Set DataCombo.DataSource = rs
With DataCombo
.DataField = "Name"
.Refresh
End With
End Sub
------------------------------------Thanks!


--Bill
Beeeeer....Mmmmmmmmmm.
-Homer Simpson
 
Nothing pops out right away, but one thing to make it easier. Do a Msgbox of rs.RecordCount right after you open the recordset. That should tell us if the problem is with your data or the datacombo.
 
You need to set the datacombo RowSource and Listfield properties these control populating the list box portion.

Ive only used dbcombos with a data control maybe try

Set DataCombo.DataSource = rs
Set DataCombo.RowSource = rs

With DataCombo
.DataField = "Name"
.ListField = "Name"
.Refresh
End With
 
Ok thanks, and I discovered another error in my code. BUT THERE'S ANOTHER PROBLEM: it is only returning the top row! But there are a number of rows in the recordset. I'm stumped!

--Bill
Beeeeer....Mmmmmmmmmm.
-Homer Simpson
 
Hi BillyBob,

I think I know how to solve your problem.

Data Combo's are not like normal Cobo's.
The difference is, that when you populate a normal combo, you can just add Items to to, right?

Whith a Data Combo, the data source, and the data member should be from two different data sources...
I don't know why this is the case....but it is.

Try creating two data sources, Conn1 and Conn2, assign Conn1 to datasource and conn2 to datamember.

Let know if you come right, or if you don't


Thanks
x50-8
 
i had the same problem with datacombo that billybobk had. i tried all the solutions suggested here but as billybobk said,only the 1st record is being retrieved with these methods. why is that so? finally i connected it thru adodc 's coding and it worked. the code was


adodc1.ConnectionString = "Driver={Microsoft ODBC for Oracle};server=myserver;Uid=scott;Pwd=tiger"
adodc1.UserName = scott
adodc1.Password = tiger
adodc1.RecordSource = "select code from mytable"

Set cmbo1.RowSource = adodc1
cmbo1.ListField = "code"

this works. but, is it possible to fill datacombo directly without data control?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top