Solved

Ho do I use macro to force close Access 2007?

Posted on 2011-03-22
3
304 Views
Last Modified: 2012-08-13
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
Comment
Question by:wmb02
  • 2
3 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
 

Author Comment

by:wmb02
Comment Utility
capicorn1:
Would you please provide me an example of a sample "auto macro" to run a function that you described.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now