Maiol Salse Escudero
Maiol Salse Escudero

Reputation: 61

DAO: dbSeeChanges alters behavior of FindFirst method of Recordset object

Recently I needed to add the parameter dbSeeChanges to the OpenRecordset method of the Database object in order to prepare the system for SQL Server progressive migration.

The thing is that change seemingly altered the functioning of the Recordset object in the following way.

Previously, if I had a Recordset that returned no records and I used the FindFirst method it went smoothly without errors, it simply found nothing and moved on. But now, in this same scenario, that action raises the following runtime error: 3021 "No current record".

Given a recordset with that returns no records the following code runs without errors:

Dim dbCurrDB As Dao.Database
Dim rstA As Recordset

Set dbCurrDB = CurrentDB
Set rstA = dbCurrDB.OpenRecordset("SomeTable", dbOpenDynaset)

With rst

  .FindFirst "Id=1"

  If .NoMatch=False Then

    .Edit
      !SomeField=SomeValue
    .Uptade

  End If

End With

Given the same conditions, the following code raises that 3021 error on the '.FindFirst "Id=1"' instruction:

Dim dbCurrDB As Dao.Database
Dim rstA As Recordset

Set dbCurrDB = CurrentDB
Set rstA = dbCurrDB.OpenRecordset("SomeTable", dbOpenDynaset, dbSeeChanges)

With rst

  .FindFirst "Id=1"

  If .NoMatch=False Then

    .Edit
      !SomeField=SomeValue
    .Uptade

  End If

End With

I know how to solve the issue (although it will finally force me to correct all legacy...). What I want is to understand why this happens. What exactly did change? Something with the pointer of the Recordset object? And also, if there can be other unintended side effects.

I wonder if there are some detailed technical specifications for DAO that can show me what the heck really happens with the mehods of the Recordset object behind the scenes.

Thanks in advance!

Upvotes: 1

Views: 112

Answers (1)

Gustav
Gustav

Reputation: 55816

Check for records, or there is nothing to find:

With rst
    If .RecordCount > 0 Then
        .FindFirst "Id=1"
        If .NoMatch = False Then
            .Edit
                !SomeField.Value = SomeValue
            .Update
        End If
    End If
    .Close
End With

Upvotes: 0

Related Questions