Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to exit access app when exiting switchboard? 1

Status
Not open for further replies.

jetspin

Programmer
Mar 5, 2002
76
Hi.

What is the code to exit the access application after a user clicks on the 'exit' of a switchboard?

I see in the code of the switchboard form it only executes
Closecurrentdatabase and leave the access applicatin open maximized and user has to perform addtional step and close this down.

Thanks.
 
Hi!

If you dare;-), you could use:

[tt]application.quit[/tt]

HTH Roy-Vidar
 
Hi.

Does "If you dare" imply something dangerous to be aware of?

Thanks.
 
No it doesn't, bad attempt at humour:-( Just see that it is the last command to be executed.

Roy-Vidar
 
Hi.

I tried both suggestions and they both did not work.... If you look at a switchboard built by a 2000 db wizard, it uses a select/case statement to loop through the buttons.

If it hits a 6, it executes a closedatabase immediately and then after the last case statement there is a rs.close

I tried inserting Application.Quit and DoCMd.quit right after the closedatbase.... I also inserted rs.close after them too with still no luck.

I'll keep looking at the code, unless U can see something else. Thanks.

 
Hi.

I used the tool wizard to build a 'stop application' button and THAT works. It has a DoCmd.Quit too. So why does that work okay but not when it is in the Button Array click code?

Thanks.
 
Are you absolutely sure the command is being triggered in the first place? Perhaps you could post the sub that you're stepping through. You may want to consider throwing a debug messagebox before and after the DoCmd.Quit, just to make sure it is indeed failing.
 
jetspin

post up the code so we can look at it.

I might not know much but do I know that Application.Quit and Docmd.quit works. [thumbsup]
 
Hi.

I found out the reaons but don't know what to do...

The 'closedatabase' command executes and halts the logic right there and nothing more executes. I put a debug to watch it. So where should I put the DoCmd.Quit or Application.quit in the code? I don't want to leave any return pointers hanging. Here is the code when the 'exit appliation on switchboard is clicked.....

' Exit the application.
Case conCmdExitApplication

CloseCurrentDatabase

End Select

' Close the recordset and the database.
rs.Close

HandleButtonClick_Exit:
On Error Resume Next
Set rs = Nothing
Set con = Nothing
Exit Function
 
To test, I've just replaced the line:

[tt]CloseCurrentDatabase[/tt]

with

[tt]application.quit[/tt]

in the switchboards forms handlebutton function

in both a2k and xp, where it worked.

might be ok to close rs and set the object variables to nothing before application.quit.

Post back if you don't get it to work

Roy-Vidar
 
To add to RoyVidar comment

application.quit will release all resources so you don't really need rs.close but it is good practice to do it anyway.
 
Hi.

I'm testing with the following and it works... I just want be sure of closing the db okay.

Case conCmdExitApplication
strQuitIt = "Y" ' added this line
'''''CloseCurrentDatabase

End Select

' Close the recordset and the database.
rs.Close

HandleButtonClick_Exit:
On Error Resume Next
Set rs = Nothing
Set con = Nothing

If strQuitIt = "Y" Then '' added this conditional
Application.Quit
End If

Exit Function
 
You are adding an unnecessary step

replace strQuitIt = "Y" with Application.Quit

You're just exiting the app in a fancy way with what you are doing.
 
HI.

I understand, but I've also been searching for info on 'DoCmd.Quit acQuitSaveAll' which seems to be preferred.

Comments anyone?

Jetspin

 
Hi!

Both seem to do the trick, in such situations I try F1, where the "quit" topic shows that docmd.quit has been added for backward compatibility with Access 95. It also recommend to use the quit method of the application object.

Both methods defaults to acSaveYes (application.quit) and acQuitSaveAll (docmd.quit), but yes, lot of people use/recommend to explicitly program default properties, options, arguments etc.

Both methods also have options to either prompt or exit without saving.

HTH Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top