MS Access RunCode Macro cannot find my procedure

前端 未结 9 1391
一整个雨季
一整个雨季 2020-12-10 11:24

I\'m only posting this since I wasn\'t able to find a solution anywhere. I finally figured it out. Kind of silly really.

When using the RunCode property within an

相关标签:
9条回答
  • 2020-12-10 11:32

    Access 2013: A function called with MyFunction() from RunCode where MyFunction does not exist gives me error 2425. None of the above work for me, however, and I was still getting Error Number 2001 when the function exists and is public. Database is in a Trusted Location. No compile errors, but something in MyFunction did not work, namely

    DoCmd.ShowAllRecords 
    

    after GoToControl worked to select my subform. Real problem was my code to remove a filter with VBA. Manual for ShowAllRecords seems to indicate that this should work, but replacing DoCmd.ShowAllRecords with

    DoCmd.RunCommand acCmdRemoveFilterSort 
    

    fixed my problem.

    0 讨论(0)
  • 2020-12-10 11:32

    Access Office 365: My subroutine works when called from within VBA and used to work in Macros. Moved function text to a separate module, saved it by itself. Gave the module (not class) a unique name.

    0 讨论(0)
  • 2020-12-10 11:33

    My mistake was putting the function in a Class Module instead of a regular module.

    0 讨论(0)
  • 2020-12-10 11:34

    The database seems to need to have objects in it other than the VBA function being called as well. Without other objects (specifically a table in my case), the function is unable to be found from within the calling environment (eg Excel VBA).

    0 讨论(0)
  • 2020-12-10 11:40

    THEN I read the error message carefully. It mentions that it could not find the FUNCTION name. Apparently, the RunCode property specifically requires a "Function" not a Sub. So, I simply changed my Sub to Function and it worked fine!

    Hope this helps.

    0 讨论(0)
  • 2020-12-10 11:44

    I was borrowing a "template" vbasic text from online as a shell. And while I renamed the function in the code section, MSAccess/Vbasic did not show the name change in the function heading of the Module box so when I ran the macro which called this function it said it couldn't find it. Tried repeatedly to fix. Then I noticed the name was different in the code section of vbasic versus the heading of the function dialog box. So I changed the name manually in the heading box and it prompted me to save which I did and now it works. Maybe this is why snake software is so popular. :)

    0 讨论(0)
提交回复
热议问题