Access error reference
Access error 91: Object variable or With block variable not set
The code uses an object (Recordset, form, class, Excel) that was never created, or was released in the meantime. VBA then stops on “Object variable or With block variable not set”.
The message

Object variable or With block variable not set
On a French Access: « Variable objet ou variable de bloc With non définie ». The variable is Nothing when the code reads one of its properties or calls one of its methods.
Where it shows up
On a line that uses an object: rs.MoveNext, frm.Requery, xlApp.Workbooks.Open, gUser.Name, or inside a With … End With block.
Common causes
- a missing
Set:rs = CurrentDb.OpenRecordset("Customers")instead ofSet rs = …; - an object never created on one code path: the
Setsits inside anIfthat was not taken; - an object already released by
Set x = Nothing, or closed before being reused; - a global variable reset: after an unhandled error and a click on “End”, the VBA project is reset and global objects are
Nothing.
How to reproduce and check it
- Click “Debug” and find the object variable on the yellow line.
- In the Immediate window (Ctrl+G), type
? rs Is Nothing: True confirms the cause. - Trace the code back to that variable's
Set, and look for the path that skips it.
How to fix it
Create the object with Set before using it: Set rs = CurrentDb.OpenRecordset("Customers", dbOpenDynaset). For an object that may be missing, test it: If rs Is Nothing Then Exit Sub.
For a global object, go through a function that recreates it when needed rather than relying on start-up initialisation: If gUser Is Nothing Then Set gUser = New clsUser. Add error handling to procedures called by buttons: the project is no longer reset at the first error.
What Auscult reports
The diagnostic records error 91 with the form or button that raises it. The report explains it as “The code uses an object that was not set up beforehand: a form that is not open, a link that was not established” and suggests fixing how that object is used.
Related errors
- 2450 — can't find the referenced form, a form used without being open
- 13 — type mismatch
- Can't find project or library, when the object comes from a missing reference
- The Access error reference, code by code