Question The command or action Quit isn't available now (1 Viewer)

frozbie

Occasional Access Wizard
Local time
Today, 20:40
Joined
Apr 4, 2005
Messages
52
Hi,

I've come across a strange problem in a new contract, wondering if anyone else has discovered the cause or solution.

My client has a series of Access databases that are managed through Windows Task Scheduler on some dedicated desktop PCs. Task scheduler opens each database on a frequent schedule, and runs the main macro in each to export data and build reports. After the process is run, the macro calls action QuitAccess to close the Access application.

Using Access 2010 on Windows 7 OS SP1 64 bit 2.4Ghz 8Gb RAM

(It's quite a good system imo in order to get round restrictions they face building a SQL Server automation)

Anyway, I'm carrying out work on the databases, copying them and readying them for a system change, except when I run the macro on one database, I get an error I haven't seen before:

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 Access.
* The type of object the action 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.

The issue occurs when the macro tries to run action: QuitAccess. It errors regardless of whether Option Exit or Save All is selected.

It is running fine on the original version of the database.

And this is where is gets weird... I've just realised that in testing the changes to the macro, I've been right clicking on it and selecting run. Every time I do that, I get the error. But, when I double click on the macro, it runs and closes Access with no error. :banghead:

Does anyone know why this would be?

I've been through this and other forums searching for explanations, but although quite a few people have experienced the error, there is very little useful advice.

I've tried the suggestion here: https://access-programmers.co.uk/forums/showthread.php?t=165034

However, that just gives a slightly different error:
Run-time error '2046':
The command or action 'Quit' isn't available now.

I'm able to use VBA to close the current database, but that leaves the Access application running and it needs to close.

Looking at this thread: https://www.pcreview.co.uk/threads/access-2007-the-command-or-action-quit-isnt-available-now.3844511/

I've tried placing the QuitAccess action in a different macro and calling it from the main macro process, but that also gives the error.

I've ensured the database is set up as a Trusted Location. SetWarnings is set to Off.

I've created a test Task Scheduler and run a couple of successful tests automating the macro and both times, the application closed without any error.

So to summarise, does anyone know why the error would occur when running a macro by right clicking and selecting run (and also when attempting to quit via VBA), but no error when I double click or automate through Task Scheduler?
 

Ranman256

Well-known member
Local time
Today, 15:40
Joined
Apr 9, 2015
Messages
4,337
usu actions that 'arent available now' cant execute because the user is in another 'mode'.
An action is already pending, like if you do a save-As, but move to another window, but cannot do anything else because you didnt finish the save-As.

Is the Quit happening after some other events? What events?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:40
Joined
Feb 28, 2001
Messages
27,319
Some clarification might be in order:

It is running fine on the original version of the database.

My client has a series of Access databases that are managed through Windows Task Scheduler on some dedicated desktop PCs.

OK, so various PCs are running via Task Scheduler with a command line that triggers a macro to perform some actions that end with a QuitAccess, and most of the time they work. But you've got some that don't seem to work quite right.

does anyone know why the error would occur when running a macro by right clicking and selecting run (and also when attempting to quit via VBA), but no error when I double click

My first place to look is for a working and a non-working database file, use the File >> Options >> Current Database path to look at the settings on each to find differences if you can. Among other things "Selection" (single/double click) is one of the options you can control in that path, and I smell at least a whiff of difference.

I believe that Windows itself also has some control panel options that relate to selection actions based on single/double clicks. I'd also look into variations in those settings.

If neither of those comparison searches proves useful, I'd have to think about other places where that kind of difference in selection behavior might be controlled.
 

frozbie

Occasional Access Wizard
Local time
Today, 20:40
Joined
Apr 4, 2005
Messages
52
Hi Ranman,

Thank you for taking a look.

The quit is happening after other actions. In each database a macro runs a VBA function which exports data from pass through queries into an Excel template, then saves as a new excel file, closes the spreadsheet and quits the application, followed by emailing the new report to a mailing list.

It is possible one or other of the VBA processes is still running preventing the quit from running, though it is odd that there is never an error when double clicking to run the macros or running through task scheduler. Only ever when right clicking to run the macro.

Mark
 

frozbie

Occasional Access Wizard
Local time
Today, 20:40
Joined
Apr 4, 2005
Messages
52
Hi The Doc Man,

Thanks for your advice.

To clarify, the processes are always running without errors through Task Scheduler.

As far as I've determined, the team has never had an issue before and so it is only because I'm using a different method to execute the macro (right clicking/run).

Since the automated process is stable and the teams standard method for manually executing is also stable, my question is only for curiosity. (it bugs me that it seems like there should be no difference, but there is something.)

I'll check out your suggestions and feed back,

Mark
 

frozbie

Occasional Access Wizard
Local time
Today, 20:40
Joined
Apr 4, 2005
Messages
52
Hi The Doc Man,

I've compared the options/properties of original version and new version (where I first had the issue) of the database and both are identical, including using double click to open an object.

We've done some more tests and the issue occurs on other databases when choosing to run a macro using right click > Run, but not when double clicking to open.

I can only think at this stage that because I've used a different method, that is the only reason I'm having the issue. It's been suggested that maybe this is a "feature" within Access 2010, that it prevents the database closing when there could be unsaved changes... Handy when debugging or developing, but will not affect automation through Task Scheduler.

As I'm running both the original and new versions of the databases from the same computer, I'm not sure why Windows settings would make a difference as whatever settings I have is allowing one action to work. However, if there is a setting that would prevent a database closing depending on how the macro was triggered, maybe that would impact it. I can't find such a setting though.

Thank you for your time. As the issue is not preventing the processes from running and there is an easy workaround, this is not holding us up.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:40
Joined
Feb 28, 2001
Messages
27,319
On further research, I find that there is also an element relating to macros in Trust Center and that it is possible for that setting to affect the way macros are run. Check for differences between good/bad databases in Trust Center settings.
 

Users who are viewing this thread

Top Bottom