Error 2486 - Cannot Perform This Action at This Time

the_utmost

Registered User.
Local time
Today, 11:04
Joined
Mar 10, 2005
Messages
40
Hi:

I am printing reports off in code. The first one prints fine. When I loop through it the second time, I get a 2486 error "Cannot perform this action at this time." From what I have read on the Internet, Access maybe repainting the form and causing the error. Therefore I took out my DoEvents statement, but not luck. Here is my code. Any idea's?

For i = 1 To rsRunningReports.RecordCount
'* Print report
Set AccessApp = CreateObject("access.application")

If blnIsOpen = False Then
AccessApp.OpenCurrentDatabase (strPath)
blnIsOpen = True
End If

AccessApp.Visible = False
AccessApp.DoCmd.OpenReport rsRunningReports!report_name, acViewNormal, strWhereSQL '*** CRASHES HERE
DoEvents '* Allow report to be sent to the printer
DoCmd.Close acReport, rsRunningReports!report_name, acSaveNo
AccessApp.Quit
Set AccessApp = Nothing

Next i
 
OK, it appears you are closing your access object, then not reopening it.
Which is a bad thing either way.
Take the access object stuff outside of your loop:

Set AccessApp = CreateObject("access.application")
AccessApp.OpenCurrentDatabase (strPath)
AccessApp.Visible = False
LOOP HERE
AccessApp.Quit
Set AccessApp = Nothing

Don't need that inside your loop.

AccessApp.DoCmd.OpenReport rsRunningReports!report_name, acViewNormal, strWhereSQL
DoEvents '* Allow report to be sent to the printer
DoCmd.Close acReport, rsRunningReports!report_name, acSaveNo

Your Doevents and DoCmd close is running against your local copy of Access since they are not prefixed with the Access Object, I don';t think you need a doevents anyway, you made your inistance of access invisible...

This code becomes un-needed:
If blnIsOpen = False Then
AccessApp.OpenCurrentDatabase (strPath)
blnIsOpen = True
End If

Do you require another access instance to run this?
IMO anyway
 
I tried it your way and I got error 91 "Object variable not set." So I tried it like this and it worked:

For i = 1 To rsRunningReports.RecordCount
'* Print report
Set AccessApp = CreateObject("access.application")
AccessApp.OpenCurrentDatabase (strPath)
AccessApp.Visible = False
AccessApp.DoCmd.OpenReport rsRunningReports!report_name, acViewNormal, strWhereSQL
DoEvents '* Allow report to be sent to the printer
DoCmd.Close acReport, rsRunningReports!report_name, acSaveNo '* The user can save the data in the last parameter but here we turn it off
AccessApp.Quit
Set AccessApp = Nothing

Next i

Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom