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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to Open an Access Report

Status
Not open for further replies.

hsp7777

Programmer
Jan 11, 2005
67
US
Greetings,

I have the code below (in VB 6.0) and am attempting to open an existing report (in Access 2000) in Print Preview mode. However, I receive the following error when it gets to the line of code, "acapp.DoCmd.OpenReport ...":

"Runtime error 2486: You can't carry out this action at the present time."

As far as I can tell, I have the necessary references checked. Any idea as to why this is happening?

Thanks in advance!

hsp7777

Code:
Dim acapp As Object
Dim db As DAO.Database
Dim strDateText As String
Dim strReportName As String
Dim wrkjet As DAO.Workspace

strReportName = "rptPrintTasks"
Set wrkjet = CreateWorkspace("", "admin", "", dbUseJet)
Set acapp = CreateObject("Access.Application")
acapp.Visible = True
Set db = wrkjet.OpenDatabase("C:Sample2.mdb", True)
acapp.DoCmd.OpenReport reportname:=strReportName,
View:=acViewPreview (Code fails here)
End Sub
 
Could it be that the access application object isn't aware of the database opened through the workspace object?

Would the following work?

[tt]Set acapp = CreateObject("Access.Application")
acapp.opencurrentdatabase("C:\Sample2.mdb")
acapp.DoCmd.OpenReport reportname:=strReportName, _
View:=acViewPreview[/tt]

Roy-Vidar
 
That seems to work fine. Thanks so much. Now I have a really dumb question. Is there any way to keep Access open (with the report still visible) even after the VB routine finishes? Currently, as soon as the VB routine completes, Access is closed (along with the accompanying report).

Thanks!

hsp7777
 
Sorry, addressed only the opening of the report, you may want to keep the

[tt]acapp.Visible = True[/tt]

else, I don't know (perhaps set acc to nothing?).

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top