Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2

    Question Unanswered: Fire code when a database is closed

    Hi all

    I'm finishing a database for a colleague at work, and there's one thing I'd like to do, but can't work out how (or if it's possible). Is there a trigger that can be used to run code (either a sub or a macro) when a database file is closed? I'm familiar with AutoExec for firing code when it opens, but while Word VBA has a host of Auto* macro names, they seem to be missing from Access.

    Any thoughts?

    TIA!
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    not sure what you mean
    do you mean run something when the db closes
    or do you mean run something when the db is not being used by others

    you can execute Access VBA code or macros which can be called as parameters as part of command line switches. you can invoke those calls as part of a windows scheduler event.
    do a google for Access Command Line Switches

    ..a word of caution though. because its an unsupervised process you need some very careful thought in designing the process, so you know what has run, whats been changed, whether the changes were successful and so on.

    in my books its a smart call not to use the autoexec macro for these sort of tasks, primarily as it possible for someone nosing through the code to open the db and fire off the auotexec process.

    you process can be either a macro or a function/code module. windows scheduler determines the frequency/time the event occurs
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    When the database is open, you open a form (it can be hidden) with the code (or a call to the code) you want to be executed when the database is closed in its OnClose or OnUnload event code.
    Have a nice day!

  4. #4
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    Healdem - I'm looking for something like AutoExec, but to fire when the database closes rather than opens.

    Sinndho - that looks close to what I'm looking for, thanks!
    10% of magic is knowing something that no-one else does. The rest is misdirection.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •