Close Access upon closing my database

G

Guest

I have a Close button on my switchboard that (surprise, suprise) shuts my
database.
This leaves the main Access screen open, with just the toolbar at the top
and a full-sized empty grey screen.
We would much prefer it that when users close the mdb, Access would be
closed completely too.
I guess it's just a case of adding something to the code for the switchboard
Close command, and I tried quit.application but no good. So help me please...
Thanks
CW
 
G

Guest

Hi CW,

Try this, in combination with a very small text box (width = 0, height = 0)
that is named txtHidden (takes focus off of the command button the user
clicked):


Private Sub cmdExitApp_Click()
On Error GoTo ProcError

Dim intResponse As Integer

intResponse = MsgBox("Do you want to close this application?", _
vbQuestion + vbYesNo, "Exit Application...")

If intResponse = vbYes Then
DoCmd.Quit
Else
Me.txtHiddenExit.SetFocus
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in cmdExitApp_Click event procedure..."
Resume ExitProc
End Sub


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
T

tina

from Access97 Help:

"Remarks

The Quit method of the DoCmd object was added to provide backwards
compatibility for running the Quit action in Visual Basic code in Microsoft
Access version 7.0. It's recommended that you use the existing Quit method
of the Application object instead."

the syntax is

Application.Quit

there is an argument in the Quit method, with three choices, one of which is
the default. suggest you read up on the Quit Method in Access Help, so
you'll understand how the argument options work.

hth
 
G

Guest

Rather than putting the code to quit Access in the button's Click event
procedure, put it in the switchboard form's Close event procedure:

Application.Quit

This will ensure that the Access is closed however the user closes the
database, e.g. from the menu bar, rather than just from the command button.
This assumes that the switchboard form remains open, even if hidden, while
the database is open of course.

Ken Sheridan
Stafford, England
 
G

Guest

Thanks to all for your suggestions - this is working perfectly now when I
close the Switchboard. Great.
Many thanks
CW
 
G

Guest

I tried this myself and it worked just fine, however, I now cannot edit this
switchboard form because it apparently closes the for to open in design mode,
but as it closes, well....the application quits. Any thoughts on how to fix
this? I'm stumped.
 
M

M Skabialka

Assuming you used the standard switchboard template:
Can you get to your database window, where there are tabs for the tables,
queries, forms, etc?
Highlight the Switchboard form and select Design. Open the properties
window, Event, and open the code window for On Current.

Also in the same module as the On current code is a Private Function
HandleButtonClick(intBtn As Integer)

This should have your close application code; mine uses:
.......
Const conCmdExitApplication = 6
..........
Select Case rs![Command]
.......
' Exit the application.
Case conCmdExitApplication
CloseCurrentDatabase
.......
End Select

When I click this button the database closes but NOT the application.
In another database I use
DoCmd.Quit

Which closes the database and MS Access.

Mich
 
G

Guest

Even in the database window, if I select Design, the application quits as I
mentioned before.

M Skabialka said:
Assuming you used the standard switchboard template:
Can you get to your database window, where there are tabs for the tables,
queries, forms, etc?
Highlight the Switchboard form and select Design. Open the properties
window, Event, and open the code window for On Current.

Also in the same module as the On current code is a Private Function
HandleButtonClick(intBtn As Integer)

This should have your close application code; mine uses:
.......
Const conCmdExitApplication = 6
..........
Select Case rs![Command]
.......
' Exit the application.
Case conCmdExitApplication
CloseCurrentDatabase
.......
End Select

When I click this button the database closes but NOT the application.
In another database I use
DoCmd.Quit

Which closes the database and MS Access.

Mich

hparker said:
I tried this myself and it worked just fine, however, I now cannot edit
this
switchboard form because it apparently closes the for to open in design
mode,
but as it closes, well....the application quits. Any thoughts on how to
fix
this? I'm stumped.
 
M

M Skabialka

Maybe the database is corrupted? Make a copy then try this at a command
prompt.

msaccess.exe /decompile "C:\Copy of YourDB.mdb"

Recompile it when you are done.

hparker said:
Even in the database window, if I select Design, the application quits as
I
mentioned before.

M Skabialka said:
Assuming you used the standard switchboard template:
Can you get to your database window, where there are tabs for the tables,
queries, forms, etc?
Highlight the Switchboard form and select Design. Open the properties
window, Event, and open the code window for On Current.

Also in the same module as the On current code is a Private Function
HandleButtonClick(intBtn As Integer)

This should have your close application code; mine uses:
.......
Const conCmdExitApplication = 6
..........
Select Case rs![Command]
.......
' Exit the application.
Case conCmdExitApplication
CloseCurrentDatabase
.......
End Select

When I click this button the database closes but NOT the application.
In another database I use
DoCmd.Quit

Which closes the database and MS Access.

Mich

hparker said:
I tried this myself and it worked just fine, however, I now cannot edit
this
switchboard form because it apparently closes the for to open in design
mode,
but as it closes, well....the application quits. Any thoughts on how
to
fix
this? I'm stumped.

:

Rather than putting the code to quit Access in the button's Click
event
procedure, put it in the switchboard form's Close event procedure:

Application.Quit

This will ensure that the Access is closed however the user closes the
database, e.g. from the menu bar, rather than just from the command
button.
This assumes that the switchboard form remains open, even if hidden,
while
the database is open of course.

Ken Sheridan
Stafford, England

:

I have a Close button on my switchboard that (surprise, suprise)
shuts
my
database.
This leaves the main Access screen open, with just the toolbar at
the
top
and a full-sized empty grey screen.
We would much prefer it that when users close the mdb, Access would
be
closed completely too.
I guess it's just a case of adding something to the code for the
switchboard
Close command, and I tried quit.application but no good. So help me
please...
Thanks
CW
 
G

Guest

One approach could be to declare a blnUserMode Boolean variable as Public in
a standard module and, via an autoexec macro, execute code to set its value
to True (along with any other tasks you want to undertake at start up). Make
the closing of the application via the switchboard's Close event procedure
conditional on blnUserMode = True.

When you wish to develop the application by pass the opening routine by
holding down the Shift key as you open the application. If you wished you
could also employ some internal mechanism to change the value of the variable
to False so that you can open the switchboard in design view if the
application has been opened normally.

Ken Sheridan
Stafford, England
 
G

Guest

I simply deselected the switchboard form in the startup options so I could
edit it and undo what I did....now I can persue some of the other options to
the original problem. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top