Printing Report from Disconnected Project with SQL Server Data

D

dougloj

I have a disconnected Access 2003 project (adp)that I use to access an
SQL Server 2000 database. I open and close the connection from the
project to the database to get and store data as needed in the project
with no problem.

Can anyone tell me how to print a report within the project VBA code
using data from the database?

I've tried the folling code :

Set conn = New ADODB.connection
conn.ConnectionString = <connection string info ...>
conn.Open
conn.CursorLocation = adUseClient
DoCmd.OpenReport stDocName, acNormal
conn.Close

When I run this code, I get an error which says:

"Access was not able to perform this operation because the project is
not connected to a SQL Server database."

Any ideas would be welcomed!

Thanks for the bandwidth.

- Doug
 
N

Norman Yuan

Your code (opening/closing an ADODB.Connection) does nothing: open
connection and then close it. The DoCmd.OpenReport() method uses
CurrentProject.Connection to perform data accessing. Since your adp is
disconnected, your report will not run, of course.

If you have to use the code to connect the ADP for opening the report and
then disconnect the adp afterward, you can use
CurrentProject.OpenConnection()/CloseConnection() method, something like:

CurrentProject.OpenConnection connectionString
DoCmd.OpenReport .............
CurentProject.CloseConnection

(I never tried this, not sure it will work or not, though).
 
Top