Results 1 to 5 of 5
  1. #1
    Johnny12 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2012
    Posts
    31

    Macro to Press Button or Run VBA


    I have a simple database that imports several excel files, churns them up and creates a new excel report. Currently you open the DB, the autoexec macro runs to do all the work, then a form opens with a button for you to press to run the report. I use VBA on the On Click event to export to Excel. There is no reason for the users to do anything else in this DB except run this report. Is there a way I can move the VBA to be run in the AutoExe macro or for the form to open and the button be pressed, then the DB close? Thanks!

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Just add an entry to your macro with RunCode(YourVBA_ExportFunction) as the action; note that you should have it as a VBA function not a sub.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Can have function in general module called by the macro and that function executes button procedure. Button procedure cannot be Private.

    Would be best to move the working code to a general module as a Function then it can be called by macro or button. But then I suppose the form is no longer needed.

    What do you mean by "excel report" - just exports to a new Excel file?
    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
    Johnny12 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2012
    Posts
    31
    Quote Originally Posted by Gicu View Post
    Just add an entry to your macro with RunCode(YourVBA_ExportFunction) as the action; note that you should have it as a VBA function not a sub.
    Cheers,
    That worked perfectly, thank you!

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Deleting a Form at the press of a Button
    By LeonS in forum Access
    Replies: 9
    Last Post: 09-28-2021, 01:25 AM
  2. Replies: 2
    Last Post: 08-23-2017, 02:18 PM
  3. How to delete certain fields in record on button press
    By NikoTheBowHunter in forum Access
    Replies: 6
    Last Post: 05-31-2017, 10:43 AM
  4. Increment number field on button press.
    By Homegrownandy in forum Access
    Replies: 3
    Last Post: 03-11-2016, 05:54 AM
  5. On button press should update the year
    By jamril in forum Access
    Replies: 3
    Last Post: 02-26-2013, 11:58 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
  •  
Other Forums: Microsoft Office Forums