Search code examples
ms-accessado

Is it save to change the cursor position of an ADODB.Recordset that is attached to a ListBox?


I need to do some tasks with a Recordset that is attached to a ListBox. For ex. looping over to search for records.

Is there any problem doing so?


Edit Well better I explain what I trying to do:

The Recordset contains a List of records that is displayed in a ListBox. The user can navigate and select one entry. The selected record will queried with full detail and then displayed in the form.

The user can change the filter and reload the Recordset and as result the ListBox conatins different Records.

Now I want to loop over the new loaded recordset to find out if the currently in the form displayed record is still in the Listbox.


Solution

  • To iterate over bound recordsets, you generally should just clone them:

    Dim rsClone As ADODB.Recordset
    Set rsClone = MyListbox.Recordset.Clone(adLockReadOnly)
    With rsClone
        If Not .EOF And .BOF Then .MoveFirst
        Do Until rs.EOF
            'Etc
    

    I've never really encountered errors on a recordset that just was being used as a row source, though, but I haven't really tried since I tend to always use a clone.