Click to See Complete Forum and Search --> : Updating a combobox


gknierim
February 5th, 2000, 10:43 AM
I am using a ADO recordset. I have a few questions.
1) I am currently using a regular combobox instead of the DBCombo box. What is the main difference between these two and which one should I be using?

2) How do I refresh the contents of a combolist if I delete a record from the recordset? I have tried .Refresh, .Update, and .Resync and nothing seems to work. I also read that the .Resync will only work if the form is a MDI child. My form is not a child and I don't want it to be a child. Here is my existing code so far when the user deletes a record from the recordset:\

Dim Response
Response = MsgBox("Are you sure you want to delete " & cboList1.Text & "?", vbQuestion + vbYesNo, "Delete driver")
If Response = vbYes then
With datPrimaryRS.Recordset
.Delete
.Update
.MoveNext
If .EOF then .MoveLast
End With
Exit Sub
End If



Do I really need the .Update also?

Any help would be greatly appreciated!!
Thanks,
Greg

Spectre
February 5th, 2000, 10:34 PM
The DBComboBox is a databound control and allows easy binding to a field in a recordset, however this ease of use also restricts how much you can programatically control it's behavior. With a normal ComboBox you have to do everything yourself this makes it harder to use (in conjunction with a recordset) but you have much more programatic control over it's behavior. I prefer to use a normal ComboBox, but it is a matter of exactly how much control over the control's behavior that your application needs. Now to answer your second question:

The easy way - use the ComboBox's Clear method to clear all entries from the ComboBox the use the MoveFirst method of your recordset to get back to the beginning of the recordset, then refill the ComboBox just like you did the first time. This time the deleted entry will no longer be there. (Note: If your ComboBox has a lot of entries, this method can take a while to process) - The hard way - Determine the index number of the deleted item (by iterating through the ComboBox items and comparing the entries to the one about to be deleted) and use the RemoveItem method of the ComboBox to remove that one item. - If you are adding and deleting I would go with the first method since it refills the ComboBox from scratch each time.

gknierim
February 6th, 2000, 07:13 AM
Thanks for the help! I tried a DBCombo box first and you're right, it did restrict what I could do and thats why I thought I was doing something wrong. As far as the index, I think thats probably what I'll do. I have been thinking that I could do that. Its a little harder but it should't be a problem. If it is, I'll go with the easy way. Thanks, again.