• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Ho do I use macro to force close Access 2007?

I have a macro that runs from one acces database to export a table to a different database.  The purpose is to update the table with current daily data.  The user of the database to be updated often forgets to close the database to be updated or is runing a query or macro in it.  This causes my database with the auto macro to error out because the database/table to be updated is being used by a different user.

QUESTION:  Is there a way end the macro and force close the database when an error dialogue box is open?  My desired end result would be to stop the macro from trying to update the external database and close the current database out.  The reason is that a separate database macro runs at a later time.
0
wmb02
Asked:
wmb02
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
modify your "auto macro" to run a function that will export a table to the other database.
In the function, you can trap the error and likewise exit (quit) the application.
0
 
wmb02Author Commented:
capicorn1:
Would you please provide me an example of a sample "auto macro" to run a function that you described.
0
 
Rey Obrero (Capricorn1)Commented:
first create a function in a regular VBA module

function myexport()
on error goto err_handler

'your codes to export the table and etc...


err_handler:
  if err.number=<the error number you are getting>
     err.clear
     docmd.quit
    else
      'other errors coding
  end if

end function

* save module as modExport or any name you want except the name of any function

now in your AUTOEXEC macro add an action
RunCode


Function Name myexport()


0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now