Soltion for You can't exit MS Access error message

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?
 
C

Carl Bailey

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
 
B

bhicks11 via AccessMonster.com

You have AccessApp.Quit within the loop. Looks like you are trying to close
the application while you are running a process.

Bonnie
http://www.dataplus-svc.com

Carl said:
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
What is the Macro doing? What is it looping through? Are you trying to exit?
[quoted text clipped - 6 lines]
 
D

dch3

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top