Results 1 to 11 of 11
  1. #1
    steven7 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    May 2016
    Posts
    13

    Auto exe macro

    Hi,

    I want to run a macro that from a desktop icon

    • deletes existing files
    • writes in the replacements
    • closes access




    The macro runs fine on its own, but I have to convert to VB to add the kill function. I get asked for macro name when I run this. Any ideas?



    Option Compare Database
    '------------------------------------------------------------
    ' Loading_schedules
    '
    '------------------------------------------------------------
    Function Loading_schedules()
    On Error GoTo Loading_schedules_Err
    Kill "\\filepath
    Kill "\\filepath
    DoCmd.OutputTo acOutputQuery, "Loading Patterns", "ExcelWorkbook(*.xlsx)", "filepath", False, "", , acExportQualityPrint
    DoCmd.OutputTo acOutputQuery, "PAD Schedule", "ExcelWorkbook(*.xlsx)", "\\filepath", False, "", , acExportQualityPrint
    DoCmd.Quit acExit

    Loading_schedules_Exit:
    Exit Function
    Loading_schedules_Err:
    MsgBox Error$
    Resume Loading_schedules_Exit
    End Function

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    in the macro, choose:
    RUNCODE Loading_schedules()

  3. #3
    steven7 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    May 2016
    Posts
    13
    Quote Originally Posted by ranman256 View Post
    in the macro, choose:
    RUNCODE Loading_schedules()
    Excuse my basic knowledge, do I write that in the VB?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    No, these commands go into the autoexec macro, to run the VB shown above.
    is that what you wanted?

  5. #5
    steven7 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    May 2016
    Posts
    13
    Quote Originally Posted by ranman256 View Post
    No, these commands go into the autoexec macro, to run the VB shown above.
    is that what you wanted?
    if that will allow me to run the macro from a desktop shortcut then yeah. I'm not back in until tomorrow so I will try it then. Thanks.

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If you name a macro AutoExec, it runs whenever the database is opened (provided that VBA/Macros are enabled).
    So if you have a macro named AutoExec in your database, and just have a shortcut to that database on the Desktop, clicking it to open the database will in essence run the macros.

  7. #7
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Put this command in the autoexec macro,the when i
    it he db opens, it will run.

  8. #8
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    DoCmd.OutputTo acOutputQuery, "Loading Patterns", "ExcelWorkbook(*.xlsx)", "filepath", False, "", , acExportQualityPrint

    Do you need \\filepath on this line?

  9. #9
    steven7 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    May 2016
    Posts
    13
    Quote Originally Posted by Bulzie View Post
    DoCmd.OutputTo acOutputQuery, "Loading Patterns", "ExcelWorkbook(*.xlsx)", "filepath", False, "", , acExportQualityPrint

    Do you need \\filepath on this line?
    Yes, it specifies the filepath where the file will save to

  10. #10
    steven7 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    May 2016
    Posts
    13
    Quote Originally Posted by ranman256 View Post
    Put this command in the autoexec macro,the when i
    it he db opens, it will run.
    Ok, so I created the autoexec macro, which runs as soon as I open the database. Works fine. However, I cannot add the kill function unless I convert to VB which then will not autorun?

  11. #11
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Ok, so I created the autoexec macro, which runs as soon as I open the database. Works fine. However, I cannot add the kill function unless I convert to VB which then will not autorun?
    Create a one-line function in VBA that contains your kill command.
    You can then run that function from a Macro using the "RunCode" command.

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

Similar Threads

  1. Auto run converted Macro
    By steven7 in forum Macros
    Replies: 3
    Last Post: 06-09-2016, 11:26 AM
  2. macro auto filling
    By chr1stoper1 in forum Macros
    Replies: 6
    Last Post: 09-12-2015, 10:32 AM
  3. macro to auto upload data
    By chr1stoper1 in forum Macros
    Replies: 2
    Last Post: 08-05-2015, 09:21 AM
  4. Macro to Auto Filter
    By skinny1434 in forum Access
    Replies: 1
    Last Post: 06-14-2012, 01:13 PM
  5. Replies: 3
    Last Post: 04-07-2012, 09:01 AM

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