VBA Cannot Quit Access program either in the code or using a macro

KSP

New member
Local time
Today, 10:49
Joined
Oct 2, 2014
Messages
5
I received the below error message when I built a macro to kick off a function and quit to close MS Access.
I have a few questions that I hope the Access Gods can answer for me:
1. I created the database in the 2007 version. It is not read-only. When ask for elements to put in the macro, the system should only show me elements that is available for the user to use. If I am able to select the 'Quit' why am I getting the error below?
2. Here is what I have done to avoid this error:
- Made the directory where the database resides Trusted.
- I have made all content available and enabled macros at the opening of the database as a default.
-I have used the DoCmd.Quit in my code and I still get a 2046 error.
Can any explain why I can't quit and exit Access on command?
The command or action 'Quit' isn’t available now.
*You may be in a read-only database or an unconverted database from an earlier version of Microsoft Office Access.
*The type of object applies to isn't currently selected or isn't in the active view.
Use only those commands and macro actions that are currently available for this database.
 
It may help if you showed us all the steps in the macro, although I suspect it might be better to attach some simple VBA code to a button on a form to achieve your result.
 
I have a macro Abatement which calls function TestFunction which calls the abatement function:

Private Function TestFunction()
Abatement <--function
End function

I get the error 'Quit' isn't available. Even if "DoCmd.Quit" is the only line of code in the function.


If I add the available Quit command to the Abatement macro as

RunCode TestFuntion()
Quit Exit

I get the above lengthy error message
.
Maybe this will help. If I go directly to the Abatement function the DoCmd.Quit works. If I use the macro I get the above error messages.
 
Have you tried calling the macro something other than Abatement - it's confusing me reading it and may be causing similar confusion to Access!

What is in the Abatement function?
 
The Abatement function queries my SQL database and send abatement letters to landlords.

Abatement Macro--->TestFuntion()--->Abatement Function

I changed the name of my macro. I still get the same error. I forgot to mention that the version of Access is 2007.
 
Tried Application.Quit. I got the same error.
 
What else is running? There may be a procedure running or a Recordset open that is not *finished* and therefore Access can't close.
 
I thought of that as well, so I removed all code instead of the DoCmd.Quit command. Like I said above. If I run the Abatement function itself the quit command execute but if the macro calls the function I get Quit isn't available. I know this works I just cannot understand why this is a problem.

Also, even if the recordset is getting data from a query the lines of code should be running serially so the recordset line should complete before moving on to the next line.
 
I'm curious about this. Can you post the database?

I've seen Access not shut down cleanly if you declare a global database variable in a standard module, and assign it the value of CurrentDb . . .
Code:
private m_dbs as dao.database

sub test
    set m_dbs = currentdb
    application.quit
end sub
. . . but that never caused an error, it just left an instance of Access running that you couldn't interact with. But I just tested this in Access 2007, and it shuts down fine.

Anyway, like I say, curious to see this happen,
 
...
Also, even if the recordset is getting data from a query the lines of code should be running serially so the recordset line should complete before moving on to the next line.
Logical thought it such, but in practice it is not always the case, therefore, it helps sometimes to insert a "DoEvents" to allow the system to finish it's job.
 
KSP,

If the Recordset is open and running the DoCmd.Quit will not work until it is done. If you are running this from code and do not close the Recordset the DoCmd.Quit will not work. You can do as JHB suggests and use DoEvents but if running from code I would suggest you close the Recordset.
 

Users who are viewing this thread

Back
Top Bottom