tags:

views:

620

answers:

3

We are importing some code modules into an Access 2002 application using the below line in VBA

Application.VBE.ActiveVBProject.VBComponents.Import (strFileName)

This part works fine, the line immediately following attempts to save the new class to the project. The only way that we can see to do this is using DoCmd:

DoCmd.Save acModule, strModuleName

SOMETIMES, this results in error 2486: You can't carry out this action at the present time.

A longer version of the error gives the following:

You can't carry out this action at the present time. You tried to run a macro or used the DoCmd object in Visual Basic to carry out an action. However, Microsoft Access is performing another activity that prevents this action from being carried out now.

The fact that this says "Access is performing another activity" seems to make sense as we only get the error sometimes. Is there a way to know what is is busy doing and waiting for it to finish? Or is there a better way to implement the importing of modules?

I thought about writing something that would while until module.Saved property is true, but this code is nasty enough without that....

A: 

Try putting a DoEvents call just before your save. That may help Access finish whatever it's doing.

DJ
A: 

Since Access 2000, the VBA project is stored as a single BLOB field in a single record in one of the system tables. This means that you're executing code from the same project you're trying to save, and I'm not sure this is possible. It sounds conceptually very problematic.

David-W-Fenton
A: 

You could try using the undocumented commands Application.SaveAsText and Application.LoadFromText instead.

Tim Lentine