Results 1 to 5 of 5

Can I run a VBA code from a macro?

  1. #1
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    102

    Can I run a VBA code from a macro?

    I want to run some code at startup when I open the db.


    I created a new function and tried RunCode Myfunction() in a macro but that returns it can't find the function name. I tried with other functions which I know work and get the same error.

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,775
    Two ways to go about this:

    1. Create an AutoExec macro (see: https://support.office.com/en-us/art...8-a4755e548124)

    2. Set a Startup Form (a form that automatically opens when the database is opened), and put VBA code in the On Load event of that form.
    See: https://support.office.com/en-us/art...c-e5d5adbff1df
    and https://docs.microsoft.com/en-us/off...cess.form.load

    I usually opt for the second method, as VBA gives you more flexibility than Macros.
    Using Access 2007
    Proficient in Access, Excel, VBA, and SQL

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    47,842
    Functions are in a general module?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    102
    The AutoExec is where I wanted to go, I already have it and wanted to add to it. Currently it's running queries but I wanted to add code. I thought about just calling a form but did not know how to run the code with on open so I'll do that then, thanks.

  5. #5
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    102
    Quote Originally Posted by June7 View Post
    Functions are in a general module?
    Yes they are in the module section

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

Similar Threads

  1. Macro Code Help
    By Chris12 in forum Access
    Replies: 4
    Last Post: 05-28-2019, 11:09 AM
  2. Help with NPV Macro Code in VBA
    By BigNasty in forum Macros
    Replies: 6
    Last Post: 11-21-2016, 10:39 PM
  3. Macro Code Clean up
    By lonesoac0 in forum Macros
    Replies: 0
    Last Post: 08-01-2016, 07:37 AM
  4. Help with access code (macro?) please
    By visidro in forum Programming
    Replies: 10
    Last Post: 03-15-2013, 05:56 PM
  5. VBA code/Macro help please.
    By Davidyam in forum Access
    Replies: 1
    Last Post: 02-26-2012, 09:59 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