Forum Discussion
SuperUser20
Nov 02, 2021Copper Contributor
Regarding macros and function in Microsoft access
Hi, I have created one function in Microsoft access and I am trying to run that function using autoexec macro, but I am getting the error as shown below even if I am using the same function name tha...
isladogs
Nov 17, 2021MVP
Try changing to acSpreadsheetTypeExcel12xml - this is needed for .xlsx files
tims
Dec 02, 2021Copper Contributor
Try defining the function as 'Public' and see if it's then visible to the autoexec macro.
Public Function FetchData()
.....(stuff).....
End Function
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/function-statement
Public Function FetchData()
.....(stuff).....
End Function
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/function-statement
- isladogsDec 02, 2021MVP
For info, functions are always public unless specifically labelled as Private. The quote below is from the article that you linked
Also, the OP has already confirmed the function is Public
- timsDec 02, 2021Copper ContributorIt does indeed say that and I'm guilty of explicit declarations whenever possible.
Incidentally, when Option Explicit was added to the OP function I was not able to get the code to compile.
The following line of code was flagged.
DoCmd.DeleteObject Table, "data"
It compiled when changed to:
DoCmd.DeleteObject acTable, "data"
I don't recall seeing the naming conventions of the Function and Module.
That can result in the same exact error message.
By chance, did the OP name the Function the same name as the Module?- timsDec 02, 2021Copper Contributor
After intentionally naming the Function and Module the same exact name and running the Autoexec macro I was able to force the same error message as OP.
Assuming the OP has the same issue, it should throw Error 2425.
- Dec 02, 2021
Hi Colin,
I don't remember if we have already advised him to do a check inside VBA in order to see if the function is reachable at all:
1. Open the Immediate Window of VBA by pressing <Ctrl>+G anywhere in Access.
2. In the Immediate Window type the name of the function , i.e.
FetchData
and press <Enter> in this line
If the function executes, it is really public and should be reachable also for macros.
Servus
Karl
*********
Access-Entwickler-Konferenz: https://www.donkarl.com/?AEK
Access DevCon: http://AccessDevCon.com
Access FAQ (de/it): https://www.donkarl.com