You can encounter “run-time error 3159- Not a valid bookmark” error while using VBA code in MS Access. The error usually occurs while accessing or fetching records from database tables using queries, especially when using the Record.set.bookmark property.
The error can occur due to several reasons. In this article, we will discuss the methods to resolve this VBA run-time error.
What causes the “Not a valid bookmark” error in Microsoft Access?
This error can occur due to one of the following reasons:
- If property of the record set is set with an incompatible string.
- Incorrect Macro settings.
- Syntax of the Recordset.bookmark property is defined incorrectly in the code.
- Access database is damaged/corrupted.
- If you are trying to bookmark an already existing string in the code.
- If code contains incompatible datatype.
- Records in the database get corrupted or damaged.
Methods to resolve MS Access “3159: Not a valid Bookmark” error:
Follow the below mentioned solutions to troubleshoot and resolve the MS Access error “3159: Not a valid Bookmark error”:
Method 1. Check and correct Macro settings:
The “3159: Not a valid Bookmark” error can occur due to incorrect Macros settings in MS Access. You can check and verify whether your macro settings are enabled to access the macros. If not, then enable it. You can locate the Macro settings in the Trust Center in MS Access.
Follow the steps mentioned below:
- Using Admin rights in MS Access, go to File and then click
- Click Trust Center and then click Trust Center Settings.
- In the Trust Center, click Macro Settings.
- Under Settings, check whether the “Enable all macros” option is enabled. If not, then select it. Click
Method 2-Check and correct VBA code:
The “Not a valid bookmark” error can occur when MS Access fails to recognize the VBA code. The error usually occurs if the code contains incorrect queries. It might contain functions or methods that are not defined correctly. It may also contain invalid Bookmark properties, incorrect strings, variables, or references. You can open the VBA editor on your MS Access application to check and correct the VBA code.
Here’s how to check and verify the VBA code on MS Access:
- In your MS Access database, go to Database Tools Tab and then click Visual Basic.
- In the Visual Basic Editor, check the VBA code.
- Check and correct the syntaxes, typo errors, values defined in the Recordset.bookmark property (if used) etc. to resolve the error.
Method 3: Use the Decompile Command
The run-time error “3159 – Not a valid bookmark” error is one of the VBA errors in MS Access. You can use the Decompile command to resolve these VBA-related errors.
Here’s how to use the Decompile command:
- In your Windows search field, type CMD and then press Enter to open the CMD window on your system.
- Type the below mentioned Decompile command:
C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE /decompile
- In MS Access, go to Create and then click
- Click Database and then click Database Tools.
- Click Debug and then click
- Click on File and then select Save.
Method 4-Repair your MS Access Database
Corruption in MS Access database is also one of the reasons behind the MS Access error 3159. You can compact and repair your database file by running the Compact and Repair tool in MS Access.
Here’s how to use Microsoft’s inbuilt Compact and Repair tool to repair the damaged/corrupted database:
Note: First, ensure that no other users are using the MS Access database file you are trying to compact and repair.
- In MS Access, double-click Blank database.
- Click on File option and then click
- Click the option labeled Database Tools and then select Compact and Repair Database.
- In the Database to compact from window, click on the affected Access database file and double-click it.
- Click on the Compact
You will find the compacted and repaired database at the location where you had saved the database file.
The Compact and Repair tool may fail to repair the database file in certain cases when there is a severely corrupted file. You can use an advanced Access database repair tool like Stellar Repair for Access in such cases. The tool can repair highly damaged/corrupted MS Access database (.accdb/.mdb) files. Also, it allows for restoring all data, including tables, macros, modules, and other database objects, while maintaining data integrity. Also, the access database repair tool can repair password-protected forms and modules in the database. The tool supports Windows 11 and lower versions.
Conclusion:
You may fail to access the VBA projects in MS Access due to Access error 3159. Many possible reasons for this error include incorrect queries, syntaxes, typo errors in the VBA code, restrictive security settings blocking access to the macros in the files, etc. Sometimes, corrupted Access database files also cause this issue.
You can try methods discussed above to resolve the error. If the corruption in the MS Access database is behind this error, then use an advanced Access database repair tool like Stellar Repair for Access. It helps in resolving the VBA-related issues that occur due to corruption. It further allows you to preview all recoverable data without saving. You can download the tool’s demo version to check its functionality before saving it.