logo
search
VBA & Macro Problems

How to Access and Use a VBA Module Function in Microsoft Access

Kushani NimanthikaKushani Nimanthika Sep 30, 2026 868 views

Question details

The user needs to correctly call and use a user-defined VBA module function without triggering availability or undefined errors.

How to Access and Use a VBA Module Function in Microsoft Access
Product
Microsoft Access
Device & OS
not provided
Scenario
Attempting to execute or call a custom VBA function from an Access macro, query, or form.
Observed behavior
The user-defined function is not available, cannot be found, or throws an error due to spelling mistakes, incorrect scope declarations, or missing VBA library references.
Before you start

Before modifying your database code, carefully check your macro or query for any simple typing errors in the function name, as overlooked typos are the most common cause for this issue.

Solution 1Recommended

Declare the VBA Function as Public

To make a custom function accessible throughout your entire Access database, it must be explicitly declared with the Public scope inside a standard module.

By default, functions may be restricted to the module they are created in. Declaring a function as Public ensures that queries, forms, and macros across the database can interact with it.

1
Open the VBA Editor

Press Alt + F11 on your keyboard while inside Microsoft Access to open the Visual Basic for Applications (VBA) editor.

2
Locate the Standard Module

In the Project Explorer pane on the left, find the module containing your function under the 'Modules' folder.

3
Update the Function Declaration

Ensure your function definition starts with the word Public. For example, change 'Function MyFunction()' to 'Public Function MyFunction() As Variant'.

4
Compile the Database Project

Click on 'Debug' in the top menu bar, then select 'Compile [Your Database Name]'. This verifies the code and saves the changes.

Declare the VBA Function as Public
Naming Tip: Ensure that the name of your standard VBA module is not exactly the same as your function name, as this conflict can also make the function unavailable.
Free Microsoft Office alternative

Looking for a Lightweight Microsoft Office Alternative?

While Microsoft Access is robust for database design, troubleshooting VBA errors can be complicated. If you are looking for a reliable, free, and highly compatible office suite for managing data and documents seamlessly, WPS Office is highly recommended.

  1. 1. Download WPS Office: Visit the official WPS website and download the free WPS Office installer.
  2. 2. Manage Data with WPS Spreadsheet: Open WPS Spreadsheet to organize, analyze, and manage structured data efficiently as an alternative to complex databases.
  3. 3. Automate Tasks Using VBA: Press Alt + F11 in WPS Spreadsheet to access the built-in VBA editor and create macros without the strict limitations of Access.
Fully compatible with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx) formats.Built-in advanced spreadsheet features with excellent VBA/Macro support for data automation.Lightweight, completely free to download, and features a highly familiar user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Microsoft Access display an 'Undefined function in expression' error?

This error generally occurs when the function name is spelled incorrectly in your query/macro, the function is declared as Private instead of Public, or the VBA module housing the function shares the exact same name as the function itself.

Can I use a Private VBA function in an Access query?

No, a Private function can only be called by other procedures within the exact same module. To use a custom VBA function in an Access query, form, or macro, it must be declared as a Public function.

How do I fix the 'Compile error: Can't find project or library' message?

This error signifies a missing VBA reference. Open the VBA Editor, navigate to Tools > References, and look for any checked items labeled 'MISSING'. You must uncheck the missing reference or browse to link the correct file path to resolve it.