close all forms, run action query, then quit???

Steff_DK

Registered User.
Local time
Today, 22:46
Joined
Feb 12, 2005
Messages
110
I have put an action query in a close event of a form.

DoCmd.RunSql(DELETE * FROM tblLog WHERE [tblLog].[Delete]=True;)
DoCmd.Quit

The query works fine when nothing is opened, but when it's placed in the close event, records are still locked as the form is not closed, unloaded or whatever...

Where do I put the action query?
 
Put this in a public module and run it [Call it] when needed...

Code:
Public Sub CloseFormsAndAccess_Click()
    
    Do While Forms.Count > 0
        DoCmd.Close acForm, Forms(0).Name
    Loop
    
    DoCmd.RunSQL
    
    DoCmd.RunCommand acCmdExit
    
End Sub
 
Won't work since I call the function in the Form's own close event...
(It's a form with a tab ctrl with multiple subforms...)

I'm guessing it's trying to close itself, or...!?

I get runtime error "Close action cancelled" referring to
DoCmd.Close acForm, Forms(0).Name.
 
Do not put it in the Forms OnClose event. Call it from a "exit db" or "close form" command button and let the CloseFormsAndAccess() function do all the work.
 
I want to run it when I click the form's "control box" x...

What is "exit db"?
 
I was referring to you creating and using a custom command button to either close the form or close the database.

I suggest that you remove the forms control box X and use a custom "close form" button. Put the CloseFormsAndAccess() function in the custom "close form" button.
 
Is there any way to put the action query in the startup sequence instead?
Before the startup form loads?
 

Users who are viewing this thread

Back
Top Bottom