Close Report & Database in an External DB (not in the Current Data

G

Guest

I am trying to print reports from multiple closed databases from the current
databases.

I have a Sub that Opens the external database and prints the report. How do
I close the report and close the external database when done?

Here is what I have so far:

Sub PrintAccessReport()

Dim dbName As String
Dim rptName As String
Dim Preview As Boolean
Dim objAccess As Object

On Error GoTo PrintAccessReport_ErrHandler

Set objAccess = CreateObject("Access.Application")

With objAccess

dbName = "C:\A_FinSOL_Reports\Master_Source_Db\02-NDS_CSV Loan Setup
Data Acquisition.mdb"
rptName = "rpt_dropped_records"
Preview = True

.OpenCurrentDatabase filepath:=dbName
If Preview Then 'Preview report on screen.
.Visible = True
.DoCmd.OpenReport reportname:=rptName, _
view:=Access.acPreview

Else 'Print report to printer.
.DoCmd.OpenReport reportname:=rptName, _
view:=Access.acNormal
DoEvents 'Allow report to be sent to printer.
End If
End With
Set objAccess = Nothing
Exit Sub
PrintAccessReport_ErrHandler:
MsgBox Error$(), , "Print Access Report"

End Sub
 
D

Dave Patrick

When you're done;

objAccess.CloseCurrentDatabase
objAccess.Quit

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
|I am trying to print reports from multiple closed databases from the
current
| databases.
|
| I have a Sub that Opens the external database and prints the report. How
do
| I close the report and close the external database when done?
|
| Here is what I have so far:
|
| Sub PrintAccessReport()
|
| Dim dbName As String
| Dim rptName As String
| Dim Preview As Boolean
| Dim objAccess As Object
|
| On Error GoTo PrintAccessReport_ErrHandler
|
| Set objAccess = CreateObject("Access.Application")
|
| With objAccess
|
| dbName = "C:\A_FinSOL_Reports\Master_Source_Db\02-NDS_CSV Loan Setup
| Data Acquisition.mdb"
| rptName = "rpt_dropped_records"
| Preview = True
|
| .OpenCurrentDatabase filepath:=dbName
| If Preview Then 'Preview report on screen.
| .Visible = True
| .DoCmd.OpenReport reportname:=rptName, _
| view:=Access.acPreview
|
| Else 'Print report to printer.
| .DoCmd.OpenReport reportname:=rptName, _
| view:=Access.acNormal
| DoEvents 'Allow report to be sent to printer.
| End If
| End With
| Set objAccess = Nothing
| Exit Sub
| PrintAccessReport_ErrHandler:
| MsgBox Error$(), , "Print Access Report"
|
| End Sub
|
|
 

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