Runcode recieving error 2425

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kledki
    New Member
    • Jul 2019
    • 20

    Runcode recieving error 2425

    In MS Access 2010,I am trying to write some code to a module that I can then use RunCode to run from an AutoExec macro. I have written the code that I think should go in the module and get no errors when I debug/compile it. But when I try to use Runcode and run the macro I get error message 2425 which states "the expression you entered has a function name the Microsoft Access can't find." I checked to make sure that the name of the function called by RunCode was correct. So now, I can't tell what the problem is. Here is my code:
    Code:
    Function OpenExcelFromAccess()
        Dim MyXL As Object
        
        Set MyXL = CreateObject("Excel.Application")
        With MyXL
        .Application.Visible = True
        .Workbooks.Open "S:\DateCodes.xlxs"
        End With
        
    End Function
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Is it in a Standard module?
    If not then either move it to one or qualify any references to it explicitly.

    Is it defined as Public?
    Clearly not in your code. Does it default to Public if not specified? Is it visible as an option from the user interface Run Macro box (Database Tools | Run Macro)? If not then it isn't available and that is very likely because it's either not Public or not in a Standard Module.

    Comment

    • CharlesDelou
      New Member
      • May 2020
      • 1

      #3
      Same issue

      I have same issue, good hint what do you mean by standard
      module. Cant see why my module wouldn t be standard.
      Thanks
      Last edited by NeoPa; May 5 '20, 12:43 AM. Reason: Removed unnecessary quote.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        I don't generally respond at all where third parties put addenda into threads but I will do so for this one as a strictly one-off exception (IE. If you need further help you will need to post in a separate thread or see your posts removed). Your question could prove generally helpful.

        In the VBIDE (Visual Basic Integrated Development Environment) you can generally see the Project Explorer which allows you to see the Objects (Forms & Reports), the Class Modules & the Standard Modules. If you right-click and select Insert then Module it will create a new Standard Module for you.

        There are essentially three types of module :
        1. Those associated with Objects (Forms or Reports).
        2. Class Modules.
        3. Standard Modules.

        Only #3 (Standard Module) procedures, variables and constants can be referenced from anywhere in the project without qualification. The others are all Class Modules of one type or another and require qualification in any reference either from the Class or the Instance.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          In the Function Name Argument of your Macro, be sure to include the opening and closing parenthesis, as in:
          Code:
          OpenExcelFromAccess()

          Comment

          Working...