Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automation code controlling MS Access 1

Status
Not open for further replies.

Sheffield

Programmer
Jun 1, 2001
180
US
Help!!

While using VB to print out an Access report, I receive the following msgbox. Does anyone have any idea why?

2585 This action cannot be carried out while processing a form or report event

Dim MSAccess As Access.Application

Private Sub Command1_Click()
'References MS Access 9.0 object library.

Set MSAccess = New Access.Application

MSAccess.OpenCurrentDatabase ("c:\file\testfile.mdb")

MSAccess.DoCmd.OpenReport "rptResolved", acViewNormal

MSAccess.CloseCurrentDatabase
Set MSAccess = Nothing

End Sub
 
What line of code is it complaining about? Everything you have looks ok to me. You may try late binding like this:
Set MSAccess = CreateObject("Access.Application")
just to see if the problem persists. It may help you troubleshoot, but you may notice a performance hit.
 
My mistake....

This is the line causing the error msg.

MSAccess.DoCmd.OpenReport "rptResolved", acViewNormal

I would like to avoid defining Automation objects as general Object data types. The reason: VB will then query the Automation server each time I access it, and determining which kind of object I'm trying to create.

The bold line above DOES print out my report, but why the msgbox error occurs, I have no idea

Many thanks in advance for your help.
 
Unfortuately, the 'late-binding' produced the same result: the report printed, but the msgbox error displayed as well.

I am at a complete dead end.....any and all help is very much appreciated.
 
Oddly enough, placing the following code avoids the msgbox error:

Option Explicit
Dim MSAccess As Access.Application

Private Sub Command1_Click()
'References MS Access 9.0 object library.

Set MSAccess = New Access.Application

MSAccess.OpenCurrentDatabase ("c:\file\testfile.mdb")

MSAccess.DoCmd.OpenReport "rptResolved", acViewPreview
MSAccess.DoCmd.OpenReport "rptResolved", acViewNormal

MSAccess.CloseCurrentDatabase
Set MSAccess = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top