Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-08-2005, 04:09 AM
Steff_DK Steff_DK is offline
Registered User
 
Join Date: Feb 2005
Location: in damp places
Posts: 110
Steff_DK is on a distinguished road
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?
Reply With Quote
Sponsored Links
  #2  
Old 04-08-2005, 04:38 AM
ghudson's Avatar
ghudson ghudson is offline
Dazed & Confused
 
Join Date: Jun 2002
Location: USA
Posts: 6,044
ghudson has a spectacular aura aboutghudson has a spectacular aura about
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.
.................................................. ......
Reply With Quote
  #3  
Old 04-08-2005, 05:15 AM
Steff_DK Steff_DK is offline
Registered User
 
Join Date: Feb 2005
Location: in damp places
Posts: 110
Steff_DK is on a distinguished road
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.
Reply With Quote
  #4  
Old 04-08-2005, 06:13 AM
ghudson's Avatar
ghudson ghudson is offline
Dazed & Confused
 
Join Date: Jun 2002
Location: USA
Posts: 6,044
ghudson has a spectacular aura aboutghudson has a spectacular aura about
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.
.................................................. ......
Reply With Quote
  #5  
Old 04-08-2005, 06:49 AM
Steff_DK Steff_DK is offline
Registered User
 
Join Date: Feb 2005
Location: in damp places
Posts: 110
Steff_DK is on a distinguished road
I want to run it when I click the form's "control box" x...

What is "exit db"?
Reply With Quote
  #6  
Old 04-08-2005, 06:59 AM
ghudson's Avatar
ghudson ghudson is offline
Dazed & Confused
 
Join Date: Jun 2002
Location: USA
Posts: 6,044
ghudson has a spectacular aura aboutghudson has a spectacular aura about
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.
.................................................. ......
Reply With Quote
  #7  
Old 04-09-2005, 06:38 AM
Steff_DK Steff_DK is offline
Registered User
 
Join Date: Feb 2005
Location: in damp places
Posts: 110
Steff_DK is on a distinguished road
Is there any way to put the action query in the startup sequence instead?
Before the startup form loads?
Reply With Quote
  #8  
Old 04-09-2005, 07:57 AM
Rich
Guest
 
Posts: n/a
Use an autoexec macro to run your code
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 10:04 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World