Programmatically Close/Exit Database

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

Hi All,

I'd like to add a button to a form that will allow a user to close the
database. I've tried docmd.quit but it always leaves the lock file in
place, and I suspect that this is, on occasion, corrupting the database.
Even if it isn't, I'd just sleep better if the lock file would go away as
expected. I don't want the users to close the database any other way
because they are strictly data-entry people and I'd like to make things as
easy as possible.

Any suggestions?

Thanks & Ciao,

Tony
 
I'd like to add a button to a form that will allow a user to close the
database. I've tried docmd.quit but it always leaves the lock file in
place, and I suspect that this is, on occasion, corrupting the database.
Even if it isn't, I'd just sleep better if the lock file would go away as
expected. I don't want the users to close the database any other way
because they are strictly data-entry people and I'd like to make things as
easy as possible.

I suspect that your LDB file problem is not directly related to the
"DoCmd.Quit", but you can try closing all the open forms in the database to
break your data connections just prior to quitting and see if that makes any
difference:

'***EXAMPLE START
'Code to close all open forms in database,
' and then quit
Dim iCounter As Integer

'Close all forms but the current form
For iCounter = (Forms.Count - 1) To 0 Step -1
If Forms(iCounter).Name <> Me.Name Then
DoCmd.Close acForm, Forms(iCounter).Name
End If
Next

'Close the current form
DoCmd.Close acForm, Me.Name

'Quit the application
DoCmd.Quit

'***EXAMPLE END
 
It might help to know what version of Access you are
running. I am running an Access 2002 database and
created a command button and put in the click event
procedure the following code.

Private Sub cmdButton_Click()
On Error GoTo Err_cmdButton_Click

DoCmd.Quit

Exit_cmdButton_Click:
Exit Sub

Err_cmdButton_Click:
MsgBox Err.Description
Resume Exit_cmdButton_Click

End Sub

After setting up the button I tested it and there was a
two second delay but the lock file disappeared. I don't
know if that will help but the docmd.quit command works
with Access 2002. Just thought that you might like to
know.

Cameron Piper
 
Bruce & Cameron,

Thanks for the suggestions. I'll try them out and see what happens.

Thanks,

Tony
 
Hi Bruce & Cameron,

Tried your suggestions but neither work. Based on some looking around, I'm
going to check file and folder persmissions. If you have any other
suggestions, I certainly appreciate it.

Thanks & Ciao,

Tony
 
Tried your suggestions but neither work. Based on some looking around, I'm
going to check file and folder persmissions.

That would have been one of my next suggestions (it really should have been one
of the first). Another would have been to ensure that you are implementing a
split database design. See the following pages at Tony Toews' web site for more
information:

Splitting your Microsoft Access MDB into a front end and back end
http://www.granite.ab.ca/access/splitapp.htm

Corrupt Microsoft Access MDB Causes
http://www.granite.ab.ca/access/corruptmdbcauses.htm

Also, one of your users *might* be closing the database incorrectly (the *power
switch* is commonly used by less enlightened users).

:-)
 
From the Toolbar , if you use the command button (Control
Wizard turned on), click to create a new command button
at Access will walk you through.

To Close the form:
You want to click on [Form options] from the categories
options then [Close form] from the actions options

To Close the Application (database)
You want to click on [Application] from the categories
options then [Quit Application] from the actions options


Hope this helps.
 
Hi All,

Thanks for all the suggestions - I appreciate the help.

I have a few backup copies of the production database in which I make
modifications that I later transfer to production when it's not in use. I
just happened to open one of these this morning and noticed that when I used
my command button to close the form/exit the database, the lock file was
destroyed. After examining the code in the db that shuts down correctly and
the one that doesn't, I noticed that the one that shuts down correctly
doesn't have 'mousehook' code that prevents scrolling through records. Once
I comment the mousehook code out, the db shuts down as expected.

Anyone else using this code?:
http://support.microsoft.com/default.aspx?scid=kb;en-us;278379&Product=acc2000

It's working well for me in forms but I've noticed that when I make code
changes and attempt to run the code before closing & re-opening the db, it
hangs Access. I'm no code-god, so if anyone takes a look at the MS code and
notices anything that may account for the errata, please post here.

Again, thanks a million for all the help & Ciao,

Tony
 
I have a few backup copies of the production database in which I make
modifications that I later transfer to production when it's not in use. I
just happened to open one of these this morning and noticed that when I used
my command button to close the form/exit the database, the lock file was
destroyed. After examining the code in the db that shuts down correctly and
the one that doesn't, I noticed that the one that shuts down correctly
doesn't have 'mousehook' code that prevents scrolling through records. Once
I comment the mousehook code out, the db shuts down as expected.

Anyone else using this code?:
http://support.microsoft.com/default.aspx?scid=kb;en-us;278379&Product=acc2000

Thanks, Tony, for posting your findings. I'm sure there are others that can
benefit from your experience.

:-)
 
Back
Top