Public Function DoCmd Runtime Error 2486 (1 Viewer)

OliverA

New member
Local time
Today, 23:42
Joined
Apr 15, 2007
Messages
1
Hi All,

I am seeking to analyse and process a series of external MS Access databases.

As a first stage in this process I have written some VBA code as a standard function which undertakes the analysis and processing of each of these databases.

This module operates correctly when run in debug mode or from the MS Access visual basic tool bar within the database to be analysed.

However when I declare the function as a Public Function and call the module within the Criteria section of a query, as the penultimate stage in automatically manipulating a series of external databases, I experience some unexpected problems when the query is run.

I get a "Runtime Error 2486" message stating "You can't carry out this action at the present time. You tried to run a macro or used DoCmd object in visual basic to carry out an action. However MS Access is performing another activity that presents this action from being carried out now…"

The lines of code in which this error message is displayed relate to the following DoCmd methods DeleteObject, CopyObject, Rename, Close.

Apart from making the module a Public Function the code is identical in all respects to that which successfully runs in debug mode or from the MS Access visual basic tool bar.

Am I allowed to use DoCmd within a Public Function called through a query?

Any help will be gratefully appreciated,

Yours,


OliverA.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:42
Joined
Feb 28, 2001
Messages
27,172
So far as I know, yes. But there may be an issue with some of the actions of the DoCmd that interfere with the query actions. With DeleteObject, CopyObject, Rename, and Close, a common theme may be that a file lock has been taken out on something that precludes the action in question.

So the question is, WHAT object are you trying to delete, copy, rename, or close? (That is a rhetorical question. You have the code in front of you, so you will have to answer that one for yourself.) If the object is open at the time and the lock is exclusive, you might not be able to do what you wanted.

There is hope (of sorts). In debug mode, you can see the local objects window and get some details about everything that is currently open. You might be able to find some locking status info that will help.
 

Users who are viewing this thread

Top Bottom