Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 04-15-2007, 07:14 AM   #1
OliverA
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
OliverA is on a distinguished road
Public Function DoCmd Runtime Error 2486

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.

OliverA is offline   Reply With Quote
Old 04-15-2007, 08:16 PM   #2
The_Doc_Man
AWF VIP
 
Join Date: Feb 2001
Location: Suburban New Orleans, LA, USA
Posts: 11,585
Thanks: 41
Thanked 1,017 Times in 928 Posts
The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold
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.
__________________
I'm a certified grandpa (3 times now) and proud of it.
Retired over one year and survived being home all day with the wife. She must really love me.
The_Doc_Man is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mouse pointer nomenclature L'apprentis Modules & VBA 4 05-19-2006 04:43 AM
Run a function jempie Modules & VBA 5 01-11-2005 03:23 AM
Public Function arkres Queries 1 12-17-2001 01:10 PM
forms damo Forms 2 02-15-2000 02:47 PM
Changing the "control box" icon Jeff Forms 2 01-11-2000 07:35 PM




All times are GMT -8. The time now is 04:27 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World