Soltion for You can't exit MS Access error message

  • Thread starter Thread starter Carl Bailey
  • Start date Start date
C

Carl Bailey

I am running a looping macro, and receiving an error message: "You can't exit
Microsoft Access now. If you're running a Visual Basic Module that's using
OLE or DDE, you may need to interrupt the module.

Does anyone have a solution for this?
 
The macro is calling macros from other databases, then updating the final
results into a "final" table. This "final" database is where the macro is
stored.

Actual code with path and macro names changed:

Public Function Append_Data()
DoCmd.SetWarnings False

'Call Sub Databases Macros
Call Sub_Macros

DoCmd.OpenQuery "macro1"
DoCmd.OpenQuery "macro2"

'Turn warnings back on
DoCmd.SetWarnings True

'Close Access
DoCmd.Quit
End Function

Public Function Sub_Macros()
'Number of macros
Const NumberofMacros = 2

'Database/Macro Name List
Dim DatabaseName(0 To NumberofMacros) As String
Dim MacroName(0 To NumberofMacros) As String

'Database Path list
DatabaseName(0) = "path to database"
MacroName(0) = "macro inside database1"

DatabaseName(1) = "path to database"
MacroName(1) = "macro inside database2"

'Declare the variables
Dim AccessApp As Object
Dim i As Integer


'*************************************************************************************
'Database/Macro Loop

'*************************************************************************************

For i = 0 To NumberofMacros - 1

'Open the Database
Set AccessApp = GetObject(DatabaseName(i), "Access.Application")

'Run the macro
AccessApp.DoCmd.RunMacro MacroName(i)

'Close the Application
AccessApp.Quit

Next i
 
In Access, MACROS and VBA MODULES are two different things although they may
accomplish the same task. In other Office applications, a 'macro' is actually
VBA Code in a module. The terms are not interchangeable when dealing with
Access. Obviously the code you've posted resides in a VBA Module, but are you
using any MACROS to call the code? When you click on the 'MACROS' tab of the
database window do you have any objects there?
 
Back
Top