Results 1 to 3 of 3

How to get a macro object to run VBA code in a module?

  1. #1
    chromachem is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    27

    How to get a macro object to run VBA code in a module?

    I am new to access. Very familiar with Excel/VBA. We have created an access macro object called Reports. We would like to write some VBA code that will be run from the Access macro object Reports. Seems like it should be easy to run some code from the macro.

    All we want to do is write a small subroutine that will run from the macro "Reports" object.

    Here is VBA code we stuck in Module 1:



    Code:
    Sub Youhavemadeittomodule1()
    Msgbox  "You are in Module 1. You can start writing VBA code here."
    End SUb


    Tried as a function as well.

    We keep getting the following error: Microsoft Access cannot find
    the name 'Youhavemadeittomodule1' you entered in the expression.

    We tried RunCode, RunDataMacro and RunMacro from in the macro object expression builder - all to no avail.


    How do I get a macro object to run VBA code in a module?

    Thanks!

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    7,665
    make the code a PUBLIC FUNCTION. (it doesn't have to return anything)
    then in macro:
    RUNCODE myFnctn.

  3. #3
    chromachem is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    27
    PUBLIC was the key. It didn't occur to me to change the scope. I knew it had to be something simple. As soon as I made the function public, it showed up on the list of available functions. Much appreciated!!!!!!!!!!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 01-21-2015, 02:02 PM
  2. Replies: 3
    Last Post: 12-02-2014, 09:38 AM
  3. Running Code from a Module in a Macro
    By ReadyReckoners in forum Modules
    Replies: 2
    Last Post: 05-08-2013, 04:45 AM
  4. Replies: 11
    Last Post: 10-31-2012, 09:12 PM
  5. Macro/module to paste into an OLE object?
    By omahadivision in forum Modules
    Replies: 10
    Last Post: 08-29-2012, 05:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums