0
votes

I'm experimenting an issue when trying to .edit or .update a DAO.Recordset on a VBA/Access project. I'm actually using CodeVBA extension to create classes from tables automatically. The issue occurs on a class created this way.

The Recordset variable is declared this way:

Dim Recordset as DAO.Recordset
Set Recordset = CurrentDb.OpenRecordset("Ordres de travail", dbOpenDynaset)

I have those two lines in my code:

    Recordset.Edit
    Recordset.Fields("Commentaire indisponibilité").Value = NullIfEmptyString(Me.Commentaireindisponibilité)

During the execution, I am monitoring the selected record by looking at the value of primary key in the local variables panel. Before the execution of the first line, the primary key value is 1409, but during, and after, it moves to record 91! With no steps missed (I'm using step by step execution).

I'm quite disappointed by this, and I can't get to have the right record edited.

If any of you have an idea of what is going on, I'll be glad to know!

1

1 Answers

0
votes

If you are running this code inside of a Form, there is already an object named Recordset which is a Form property. The compiler is probably getting confused.

Change your variable name to oRecordset (or my favorite, rs)

Dim rs as DAO.Recordset
Set rs = CurrentDb.OpenRecordset("query", dbOpenDynaset)

With rs
    .Edit
    .Fields("field").Value = ""
    .Update
End With