| Chat with a LIVE Microsoft
Access Expert! |
||||
|
||||
|
#1
|
|||
|
|||
|
close all forms, run action query, then quit???
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? |
| Sponsored Links |
|
#2
|
||||
|
||||
|
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
__________________
.................................................. ...... Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.Well if it seems to be real, it's illusion... I am using Access 2007 with Windows XP The Advanced Search function on this forum really does work. ![]() .................................................. ......
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
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.
__________________
.................................................. ...... Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.Well if it seems to be real, it's illusion... I am using Access 2007 with Windows XP The Advanced Search function on this forum really does work. ![]() .................................................. ......
|
|
#5
|
|||
|
|||
|
I want to run it when I click the form's "control box" x...
What is "exit db"? |
|
#6
|
||||
|
||||
|
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.
__________________
.................................................. ...... Searching this forum or Microsoft.com or MSDN.com or Google is a great way to discover and learn the answers to your Access programming questions.Well if it seems to be real, it's illusion... I am using Access 2007 with Windows XP The Advanced Search function on this forum really does work. ![]() .................................................. ......
|
|
#7
|
|||
|
|||
|
Is there any way to put the action query in the startup sequence instead?
Before the startup form loads? |
|
#8
|
|||
|
|||
|
Use an autoexec macro to run your code
|
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|