Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

form exit routine In CONTROLBOX exit

To All,
From my toolbar "EXIT" option.
I run the following.

' close all recordsets and databases
DBClose All
' Unload form
UnloadMe
' Compact and Repair databases
CompactDb ("c:\folder\data.mdb")
RepairAndOpen ("c:\folder\data.mdb")
MsgBox "Project Reset"
End

I also want to run this routine from the ControlBox the Main form if someone chooses the "X"
I believe it is the
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

Is it just a matter of placing this same code in this event?
The code doesNOT run the compact and repair routines when I run this in this Event.
Thanks
fordraiders


Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Yes you should place it in Form_Unload or Form_QueryUnload.

These 2 events are triggered when the form is to be closed.

If you use the QueryUnload event, you have a parameter (UnloadMode) that says what is asking your application closing (your user or Windows).
Avatar of Fordraiders

ASKER

Emoreau,
This routine is from the(Compact and repair) msjet 3.5 programmers guide.

When I have 0 records in the database and I close the form.
This event will not fire from anywhere.

The error message says"
This database ( data.mdb) cannot be opened exclusively. The database may have been opened by another user.

I thought I taking care of this closing all recordsets and database's in DBCloseAll.


Now if I have records in the database it works fine.
It does not work with O records.
Thanks
fordraiders



Avatar of wsh2
wsh2

As to the zero count problem, why not just do a SQL COUNT test prior to closing?

-------------------------------------
The unloadmode argument returns the following values:

vbFormControlMenu (0):
The user chose the Close command from the Control menu on the form.

vbFormCode (1):
The Unload statement is invoked from code.

vbAppWindows (2):
The current Microsoft Windows operating environment session is ending.

vbAppTaskManager (3):
The Microsoft Windows Task Manager is closing the application.

vbFormMDIForm (4):
An MDI child form is closing because the MDI form is closing.

vbFormOwner (5):
A form is closing because its owner is closing.
ASKER CERTIFIED SOLUTION
Avatar of jwilson
jwilson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks
fordraiders