In Access 2010 I am trying to use custom VBA functions in a calculated column. I get 'the expression cannot be used in a calculated column'.
Here are my steps:
- Launch Access 2010.
- Create a new database "DB".
- Create a table "Table1" with a text column "Column1". Create a test row with "hello" in Column1.
- On "Create" ribbon, click "Module" at the upper-right corner, which launches VBA editor.
- In VBA editor "Project" window, there are two projects "ACWZTOOL" and "DB". Choose "DB" and select "Insert" -> "Module".
Write the following code:
Public Function TestFunc() As String TestFunc = "test" End Function
- "Debug" -> "Compile DB" passed, "Save" and closed VBA editor. Now "Module1" appears in "Modules" tab in the left pane.
- In Table1, create a calculated column "Column2", with expression "Len([Column1])", the column works properly with the value in test row being 5.
- Change the expression to "TestFunc()", the error pops up.
- I tried a few other built-in functions, it seems only the "basic" ones are supported in expression builder. E.g. "InStrRev()" is also not recognized.
According to this guide, user-defined functions are not allowed in calculated column expressions. The relevant quote is in the "Read It" section: