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

Populating a datacombo box from the form load event 2

Status
Not open for further replies.

iojbr

Technical User
Joined
Feb 12, 2003
Messages
129
Location
US
Hi:

I'm trying to populate datacombo box from ado recordset on a form load event, using code. But when I run it, the datacombo box is empty. I tried changing my cursor type to static, as one site suggested, but it doesn't correct the problem. I appreciate any help you can give. Thanks in advance. Here's the code I used.

Private Sub Form_Load()
Dim iConn As New ADODB.Connection
Dim iRec As New ADODB.Recordset
iConn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb"
iRec.Open "select PlayerName From Player", iConn, adOpenDynamic, adLockOptimistic
Set Me.DataCombo1.RowSource = iRec
Me.DataCombo1.DataField = "PlayerName"
End Sub
 
I've never worked with the DataCombo control myself but trying to get your code to work I got to the following conclusion: DataCombo is a bound control and therefore needs to be bound to a Data control.

MSDN Library Visual Studio 6.0: "Without a Data control or an equivalent data source control like the RemoteData control, data-aware (bound) controls on a form can't automatically access data."

A conclusion is only the point where one gets tired from thinking;) so I might be wrong. Maybe you can fill the DataCombo without bounding it to a data control, but it seems to me that you need to bound it first.
 
You could loop through the dataset and populate it from there.

BB
 
Yep. I'm tired of thinking. I went ahead and used a combobox and a loop procedure instead. Thanks a lot. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top