Newbie: How to quit Access with VB programming

F

Frank Krogh

I have made command button on a form with the following VB code:

Private Sub Avslutt_Click()
Application.CloseCurrentDatabase
Dim objAccess As Object
'objAccess.Visible = True
MsgBox "Microsoft Access is open; this procedure will now close it."
objAccess.Quit
Set objAccess = Nothing
End Sub


Excecuting this code closes the current database, but leaves the Access
program still running. Why?


Any suggestions?


Frank Krogh
 
B

Brendan Reynolds

Because a) the code never assigns anything to the variable 'objAccess'. The
variable does not point to the Access application, so nothing you do with
the variable will have any affect on the Access application. And b) because
your code is 'in' the current database, so once you close the current
database, your code stops. The lines after CloseCurrentDatabase will never
be executed.

Just replace the whole thing with Application.Quit - quitting Access will
close the database anyway, there is no need to close the database unless you
intend *not* to quit the application.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 

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