Microsoft Access “There Was an Error Executing the Command” – Do THIS to Fix It!

Well, it’s not surprising to come across errors when handling VBA code in Access databases. One such warning message you may face when executing a command is- “There was an error executing the command.” This error usually occurs when a macro or button fails to execute a command. In this blog, I will discover the major factors of this error along with feasible solutions to get rid of it with less effort.

Rated Excellent on Trustpilot
Free MS Access Database Repair Tool
Repair corrupt MDB and ACCDB database files and recover deleted database tables, queries, indexes and records easily. Try Now!
Download
By clicking the button above and installing Stellar Repair for Access (14.8 MB), I acknowledge that I have read and agree to the End User License Agreement and Privacy Policy of this site.

What Causes MS Access There Was an Error Executing the Command?

Microsoft Access there was an error executing the command is a result of command execution failure in the database. Nevertheless, some other causes may cause this error. Below, I have listed them:

  1. Compatibility problems
  2. Network connection problem
  3. A macro or code references an object that no longer exists (missing references)
  4. Access database corruption
  5. Large Access databases with multiple users
  6. Incorrect macro settings.

How to Fix Microsoft Access There Was an Error Executing the Command?

Follow the step-wise methods below to fix it.

Quick Fixes:

  1. Check for Corrupted Objects (Forms or Reports)
  2. Review the Macro or VBA Code
  3. Remove the Missing References
  4. Enable Macro Settings
  5. Repair Corrupted Access Database
  6. Checking for Missing/Renamed Objects
  7. Split the Large Access Database
  8. Use Error Handling in VBA

Way 1- Check for Corrupted Objects (Forms or Reports)

This error mainly appears due to corrupted database forms or reports. In such a situation, try checking for corrupted objects. Here is how you can do so:

  • Open the form/report directly.
  • If it fails, recreate it from a backup.
  • Use Compact and Repair to fix corruption.

Way 2- Review the Macro or VBA Code

Since the error is associated with the macro or button code so, it is recommended to check the VBA code.

  1. Open the database form in Design View.
  2. Check the macro settings or button and ensure:
  • The macro action is valid.
  • The command or function exists.
  • The macro is not referencing deleted controls.

Also read: Fix “Access Cannot Open a Database Created with a Previous Version” Error?

Way 3- Remove the Missing References

If you are using the TableDef.lockEdits or Recordset2.LockEdits property in your missing references, it can cause ‘there was an error executing the command.’ To fix this, simply verify & remove the missing references.

Here’s how you can do so:

  • Open the affected Access database.
  • Go to Database Tools >> click Visual Basic.

Visual Basic

  • In the Visual Basic Editor, go to Tools >> References.

Check for Missing References

  • In the opened window, check for an object library or enter library: MISSING:<referencename>.
  • If missing references are found, deselect the checkbox that seems next to it >> hit OK.

There Was an Error Executing the Command

Way 4- Enable Macro Settings

As already stated above, wrong Macro Security Settings in Access can disturb the macro performance and cause such an error. In such a situation, enabling the macro security settings can eventually fix it.

Follow the instructions below carefully:

  • Open Access file >> go to File > Options.
  • Select the Trust Center>> Trust Center Settings.
  • Now, choose Macro Settings >> “Enable all macros” 

Enable all macros

  • Finally, tap OK.

Way 5- Repair Corrupted Access Database

Most of the error messages occur due to Access database corruption. All you need to do is use Access’s utility– Compact and Repair to fix the database for free.

  • Open the corrupted Access database.
  • Go to the File menu >> click on Info 
  • Select Compact & Repair Database.

Repair Corrupt Database

If the Compact and Repair utility fails to work, you can try an all-in-one solution- Access Repair Software. This software can fix a severely corrupted file and recover all its components with 100% integrity.

* By clicking the Download button above and installing Stellar Repair for Access (14.8 MB), I acknowledge that I have read and agree to the End User License Agreement and Privacy Policy of this site.

Steps To Fix Access Database Corruption

access-repair-main-screen
previous arrow
next arrow

Way 6- Fix Microsoft Access There Was an Error Executing the Command by Checking for Missing/Renamed Objects

In case, If the code references of an object no longer exist, this error will appear. So, try to check the following things:

  • All forms, queries, or tables in use exist.
  • Object names match the code exactly.
  • There’re no typos in the object references.

Way 7- Split the Large Access Database

Split The Database

Sometimes, large databases with multiple users can trigger command execution errors in Microsoft Access. Splitting the database Backend and Front-end helps to solve it. This will also reduce corruption risks and improve performance.

Way 8- Use Error Handling in VBA

Protect your code using structured error handling:

vba

CopyEdit

On Error GoTo ErrorHandler

‘Your Code Here

Exit Sub

ErrorHandler:

MsgBox “Error: ” & Err.Description

This avoids runtime failures and shows meaningful messages to the user.

Frequently Asked Questions:

How to Activate a Command Button in MS Access?

To activate a command button in Microsoft Access, navigate to the Form Design tab, under the Controls group >> click Button. After that, go to the location on the form where you need to place the command button.

Can I Run VBA Code in MS Access?

If you want to run VBA code in Access, follow the steps below:

  • Create a new module. From the Create ribbon, select Module:
  • Then, add a Function and paste this text into your module.
  • From the menu, choose File, Save & give it a name.
  • Now, run the Function from a Macro.

How to Run Command in MS Access?

You can run the command in an MS Access database by using RunMenuCommand action from a custom menu bar, custom shortcut menu, or global menu bar.

How to Fix Microsoft Access Not Responding?

To fix Microsoft Access is not responding issue, try these tips:

  • Restart Access & PC.
  • Close the Conflicting Programs.
  • Import a Corrupted Access Database into a New Database.
  • Split the Database.
  • Run Compact & Repair Tool.
  • Check for Access Updates.
  • Run A Clean Boot.

Also Read: Fix Access Cannot Open Database It May Not Be a Database!

End Note

The “Microsoft Access there was an error executing the command” can trouble you & hamper your database work. Nevertheless, you can implement the solutions mentioned above in this post to troubleshoot it.

If the message occurred due to DB file corruption, try the Access Repair Tool. This will ultimately fix the corruption in the Access database .MDB &.ACCDB files.

References:

tip Still having issues? Fix them with this Access repair tool:

This software repairs & restores all ACCDB/MDB objects including tables, reports, queries, records, forms, and indexes along with modules, macros, and other stuffs effectively.

  1. Download Stellar Repair for Access rated Great on Cnet (download starts on this page).
  2. Click Browse and Search option to locate corrupt Access database.
  3. Click Repair button to repair & preview the database objects.

Pearson Willey is a website content writer and long-form content planner. Besides this, he is also an avid reader. Thus he knows very well how to write an engaging content for readers. Writing is like a growing edge for him. He loves exploring his knowledge on MS Access & sharing tech blogs.