Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Detect Close Application

Author  Topic 

Hyukevain
Yak Posting Veteran

66 Posts

Posted - 2004-07-30 : 06:27:56
Hello,

Every process in my application need to verified first before the process ended, such as entry data, user must click save or cancel changes before they can close the form. Is there anyway to trap the close command from Access ? I mean the close command from the access application, so when user accidently click the close button (X) in the top right of the access window, I can prevent the application to close before all process verified.

Is there any sample code that can help me ?

Regards,
Mike

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-07-30 : 08:53:42
The X button can't be captured as an event.
And there's no events that are triggered by a close application (to my knowledge).
What are you trying to do? Maybe there's other ways of tackling your problem...

Go to Top of Page

Hyukevain
Yak Posting Veteran

66 Posts

Posted - 2004-07-31 : 23:08:27
Sometimes user just click the X button without check were all the form they've openned already closed. This can make my program screw up because the final validation that triggered when form_Close event happen cannot run.
Go to Top of Page

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-08-01 : 19:32:22

Two words:

User Training.

or you could use your forms in disconnected mode so it won't matter if they close the app, but it's a fair bit of work.
Go to Top of Page

Hyukevain
Yak Posting Veteran

66 Posts

Posted - 2004-08-01 : 22:00:12
Not all user can be train to use all things correctly, sometimes, unexpected things happen, such as wrong button to click, wrong app to close, etc. We already told to users many times, and this thing still happen again and again.
We only have short time to work this problem out. So, is there any API or control or what ever that is, that can prevent the X button to close my app, or at least tell my app that the X button pressed and halt the process ?
Sorry, but I need them badly =)
Go to Top of Page

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-08-01 : 23:00:25
You can capture this using the Form_Close event procedure.

I just tested it and it works.

Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-08-02 : 00:53:04
I used to use the Form_Close event all the time to synch up an application with the central database. It gave them a status of updating repository, then closed the application when it was completed.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

Hyukevain
Yak Posting Veteran

66 Posts

Posted - 2004-08-02 : 03:15:01
Thank's, I've tried too and success.
Man, this gonna be a long way to add the Form_Close in every form in my App.

Thank's =)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-08-02 : 08:51:33
you can open up a form when your app opens, make it hidden (set visible=false), and trap the "Form_Close" on that form. that form will only be closed when the whole application closes.

i haven't tried it but it should work, or something along those lines.

- Jeff
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-08-02 : 10:06:21
You can also have only a table with a close sequence in it. You can drive the global closures of forms and the application using that table and one module. You would just need to point all the forms event to the same module then. Just a thought.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

Hyukevain
Yak Posting Veteran

66 Posts

Posted - 2004-08-03 : 23:01:46
I finnaly made it by using Form_Unload event (have little benefit in my case because I can set the Cancel variable to false when I don't want the app to close), but now the problem is my dummy form label show in my taskbar area. Can I hide it (only this form only), because sometimes user close unused application in their taskbar by right click the taskbar entry and select close command.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-08-04 : 08:48:20
as mentioned, create a form. call it "BackGroundForm". set it to the be the startup form.

Then, when the form opens, just execute whatever code you wish to execute when your app opens, and then set the form's visible property to FALSE.

[note: setting "visible=false" didn't always work reliably on the Open() or Load() events; i found it to work most reliably when i set the form's TimerInterval property equal to something like 10 (so that it goes off as soon as the form is open), and then on the TImer() event you: (1) turn the timer off (2) execute your application opening code and (3) set the visible property to false. Worked every time that way.]

then, on that form's Unload() event, you can handle what you wish when the entire application closes. Since the form is invisible, it won't have an entry in the task bar. That invisible form stays open the entire time your DB is open, and closes only when the application quits. This way, you can do whatever housekeeping you need when the app closes.

Does this make sense?

- Jeff
Go to Top of Page

Hyukevain
Yak Posting Veteran

66 Posts

Posted - 2004-08-05 : 04:04:31
TimerInterval.... thats the solution for my problem =) !!
Go to Top of Page
   

- Advertisement -