Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.RunMacro problem

Status
Not open for further replies.

JeroenNL

Programmer
Nov 28, 2002
217
NL
Hi there,

I'm running a macro in a database from within another database. I create an instance of an Access application and then call the DoCmd.RunMacro action like this:

Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strDatabase
appAccess.DoCmd.RunMacro myMacro
appAccess.CloseCurrentDatabase
Set appAccess = nothing

This works perfectly but... since 2 days this construction doesn't work anymore. Access says it can't find a specific function name. It gives this error on the DoCmd.RunMacro line so appearantly it can't find the DoCmd function? But when going into debugmode and waiting for, like, 3 seconds before (!) executing DoCmd.RunMacro, things DO work! Does anyone know what's going on and how I can solve this problem?

Thanks,
Jeroen

Bye,
Jeroen

A 3d level editor in Delphi
 
Obviously your code is too fast... ;-)
(or the db too large and not yet fully opened before it tries to run the macro)

Try this workaround:
Code:
Dim tim as Long
appAccess.OpenCurrentDatabase strDatabase
tim=timer
Do while timer < tim + 2
 DoEvents
Loop
appAccess.DoCmd.RunMacro myMacro

This should make your code wait 2 seconds before running the macro.
You can also try with a DoEvents only.
Could already solve it.

[blue]If it's stupid, but works, it's not stupid![/blue]

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
Thanks for your suggestion, i'll give it a try!

However, I already made a simple loop like this:

for i = 1 to 12000
doevents
next i

and it didn't work. Maybe your suggestion does work so i will give it a try right now. :)

Other suggestions are also greatly appriciated.

Bye,
Jeroen

A 3d level editor in Delphi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top