Access error reference
Access runtime error 3021: “No current record.”
The application has worked for years, then one day a form or button stops on “No current record”. Nothing changed in the code: the data did — an empty table, a filter that finds nothing.
The message
Run-time error '3021': No current record.
On a French Access: « Aucun enregistrement en cours. »
Where it shows up
In code that walks a recordset (rs.MoveFirst, rs.Edit, rs!Field), uses a form's bookmark (Me.Bookmark, RecordsetClone), or when a form reads its current record as soon as it loads.
Common causes
- an empty recordset: the query returns nothing and the code reads the first row anyway;
- moving past the end: after
MoveNexton the last row, the code reads another field; - a form with no record: empty table, filter with no result, or a form opened for data entry;
- a row deleted by another user between reading it and editing it.
How to reproduce and check it
- Reproduce with a filter that finds nothing, or on a copy where the table involved is empty.
- Put a breakpoint on the highlighted line and look at
rs.EOFandrs.BOF: if both are True, the recordset is empty.
How to fix it
Test before reading: If Not (rs.BOF And rs.EOF) Then …, or If rs.RecordCount > 0. In a loop, Do While Not rs.EOF … rs.MoveNext … Loop. On a form, check Me.Recordset.RecordCount or Me.NewRecord before using the current record.
What Auscult reports
This is the textbook conditional fault: it is real, but only when a condition is met. When the error comes from there being no record in the analysed copy, the diagnostic does not count it as an ordinary fault: it reports it as “fails if there is no record to show” or “fails if … is empty”, naming the source, and suggests handling that case. On your real data, it will happen as soon as the condition is met.
Measured on our test corpus: this message was recorded while analysing 27 of 965 applications.
Related errors
- 2465 — can't find the field
- 2501 — action was canceled, often a form that closes because it has no data
- The Access error reference, code by code