How-to: Run-time Error 5 "Invalid Procedure Call or Argument"

In Microsoft Access the error "Invalid Procedure Call or Argument" (sometimes followed by a "File Not Found" Error ) can have several possible causes. One or other of the remedies below will usually resolve this.

1) VBA References

These references might need updating when Access has just been upgraded or moved between machines running different versions of Microsoft Access. It is a good idea to document the references that you use.

To see the libraries an Access project has referenced, open any code window (Ctrl+G), and choose Tools ➞ References

If any references display "MISSING REFERENCE", make a note of the name, uncheck it and then scroll down to find an equivalent valid reference, most often a slightly newer version.

The essential references are:

Visual Basic For Applications

Microsoft Access xx.x Object Library

Microsoft DAO 3.x Object Library

Microsoft Office xx.x Access database engine

Those will allow you to write VBA code, address built-in access objects (forms etc) and read/write to ACCDB/MDB file respectively. Access will not let you remove these 3 libraries from your database.

Other very common references:

OLE Automation (Fonts, Pictures)

Microsoft Office xx.x Data Access Components Installed Version
(ActiveX Data Objects/ADO, OLE DB, and ODBC)

Compile all modules after adjusting references.

2) Decompile

Backup the database and decompile it with a command like this:

"C:\Program Files\Microsoft Office\Office16\MSACCESS.EXE" "C:\work\ss64.accdb" /decompile
Adjust the path to match your database and version of Microsoft Office.

If the database contains any startup code hold down the shift key to bypass it.

Once the database has been decompiled, close the Access instance completely.

Open a new Access instance, again hold down the shift key to bypass any startup code, and then compact and repair the database.

You can now recompile the VBA code by opening any module and selecting Debug ➞ Compile

3) Rebuild

Create a new database file and import all the objects into it.

4) Reinstall the latest Microsoft Office service pack.

5) Corrupt form

It is possible for the metadata around Access forms to become corrupt, make a backup of the entire Access database, delete the last few forms that have been edited (making a careful note of the names). Now copy and paste the form(s) back from the backup copy, n.b. don’t use the import feature. This will rebuild the metadata around the form.

“It’s easy to be hopeful when things are going well, he went on, but when you need to be hopeful is when things are at their worst” ~ Barack Obama


Q825796 - Access References that you must set (2003)

Copyright © 1999-2024
Some rights reserved