Accessing VBA error 2486 DoCmd.Save

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

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

This part works fine, line right after trying to save the new class in the project. The only way we can do this is using DoCmd:

DoCmd.Save acModule, strModuleName

      

SOMETIMES this results in

Error 2486: You cannot perform this action at this time.

The longer version of the error gives the following:

You cannot perform this action at this time. You tried to run a macro or used a DoCmd object in Visual Basic to perform an action. However, Microsoft Access takes another action that prevents this action from being performed.

The fact that it says Access is performing another activity

it seems to make sense as we sometimes get an error. Is there a way to find out what is busy and wait for it to finish? Or is there a better way to implement import of modules?

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

+1


a source to share


3 answers


Try placing the DoEvents call just before saving. This can help Access complete everything it does.



0


a source


Starting in Access 2000, a VBA project is stored as one BLOB field in one record in one of the system tables. This means that you are executing code from the same project that you are trying to save, and I am not sure if this is possible. This sounds very problematic.



0


a source


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

0


a source







All Articles