Discussion Locked

VB-ADO Recordset Bindings to Combo Boxes

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Mind blower here....
VB 6, ADO 2.1 Referenced, Standard Data Combos.

I've got an ADO Class module I created that is opening a client side recordset. This recordset is then applied to some fields on a form. The usual stuff. I've added a few comboboxes, which require me to use a support recordset to list the possible user selections, and also binds back to the original recordset to know what the value should be selected for the current record. The usual stuff. (Just like an Access Combo Listfor those non-vb-people reading this). At any rate, after setting my ComboBox DataSource and other related properties (DataField etc..) the main Recordset (the DataSource RS) can no longer be navigated. The MoveNext, Prev, etc, no longer work, but the RS is still open. rs.state returns adstateopen. I think the DataCombo is messing with my original rs bookmark when bound. The weird part: While stepping through code, I can step back and rerun my rs initialization (through the class module) and the combo box will NOT mess up my rs. But the very next ComboBox I setup, will cause the same error. The error returned is "Operation Canceled". Very descriptive, isn't it...

A friend of mine suggested that I use another recordset (an rs.clone) which will work, however, that defeats the whole purpose of a Data Combo and it's binding to the original recordset.

Does anyone have any suggestions, or would like to peruse some of my code?

Thanks in advance. Answers will be rated fairly.

Sincerely,
-Todd Parker

7 replies

by dragon emperor

When populating a combo from a recordset I generally consider it best to manually populate it from a recordset (in most instances you can do this upon startup, though for some purposes it needs to be refreshed more often (like before the dropdown appears). However, if I could see the code involved I may be able to figure out what it going wrong with it. Mostly likely your recordset choosing the value is locking the one providing the values in place (so to keep them both you would need to cycle though the options on the first recordset to get the second one to move, probably better to only have one binding on it).

by todd parker

As it turns out, Bill H worked with me, and he produced an example that did just that. I've already worked it out as well, by manually populating them. So even though, your answer didn't reach me in time, your answer is correct.

Thanks,
-Parker

by francodacosta

Have you considered using the BoundColumn property of the data control ?

Or if you like it you can email me your code and probably I will be able to help you

by bill_h

(Pursuant to our e-mail discussions...5 files sent via separate e-mail.)

"Parker Sample.Mdb" is an Access database; the structure is similar to the structure I outlined and you confirmed. One *major* difference is that the Level1ID fields for a project are *not* in the ProjectsTbl, but in a cross-reference table; this makes it easier (for my sample, anyway) to maintain multiple Level1IDs for a project.

The other four files pertain to the VB sample. I've simplified the code that is executed as follows:

The Form Initialize event only creates the WBSListRS object, populates the WBSCmb combo box, and sets the ListIndex property of WBSCmb to 0. If a combo box is populated, but an item is *not* selected, the combo box will not contain a value when first displayed. Setting the ListIndex property is the equivalent of clicking on an item in the list box; in addition, the Click event for the combo box is triggered.

The code in the WBSCmb_Click procedure is executed, setting the values for the WBS and ProjectName text boxes, and creating the LevelRS object and populating the Level1Cmb combo box. The ListIndex property is set to 0, triggering the Level1Cmb_Click event.

The code in the Level1Cmb_Click procedure is executed, creating the LevelRS object and populating the Level2Cmb combo box. The ListIndex property is set to 0, triggering the Level2Cmb_Click event.

The code in the Level2Cmb_Click procedure is executed, creating the LevelRS object and populating the Level3Cmb combo box. The ListIndex property is set to 0, in order to have the first item to display in Level3Cmb (Level3Cmb is the last in the series in this sample, so there is no need to trap the Level3Cmb_Click event).

In addition to the changes in the code, I used the simple combo box control for WBSCmb, Level1Cmb, Level2Cmb and Level3Cmb; from the code you sent me, I assume you are using the DataCombo control.

by todd parker

There just isn't enough I can say about this gent.

Way above and beyond the call of Duty. Bill has demonstrated a very quick learning curve for my database and it's structure, then produced a near perfect replica of the problem in an attempt to find a solution. Bill's sample code and database has given me some insight to an alternative way of doing certain things that I would not have thought of alone.

Articulate, friendly, and knowledgeable. A pleasure to work with.

Thanks,
-Parker

This discussion is closed to new replies.