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

exporting a MS Access2000 report

Status
Not open for further replies.

jasek78

Programmer
Nov 5, 2001
298
0
0
US
I have an Access2000 database with some reports. Is there a way to export the reports to an RTF file? Can someone show me a code sample?

Thank you!

jason
 
...Or if someone can show me how to create a "Snapshot" ?

Has anyone experienced problems exporting Access Reports as RTF files and/or "Snapshots" and viewing them in their respective controls (RTF/SnapshotViewer)?
I'm trying to research these two methods. I'm trying to allow a user (who has Access2000 installed) the ability to preview and print reports inside my VB program, without them having to "use" Access. I'm currently working with automation (creating an Access2000 object, then opening the DB (*invisibly*).

If you can expand the code sample to include connecting the Access object with the actual database, that would be very much appreciated...

Thanks a lot!

jason
 
Assuming that you have a Report named "rptFRED" then:


stDocName = "rptFRED"
strFileName = "c:\temp\ReportNamedFred.snp"
DoCmd.OutputTo acReport, stDocName, acFormatSNP, strFileName

put that code under a button on a form and it will create a snapshot file from rptFred and save it in c:\temp\ReportNamedFred.snp"

HTH

John
 
This does basically the same as JohnCh has given you. But shows the exports for XLS, RTF, SNP and HTML. The appAccess is a variable for Access 2000 application. If you don't pass in one of the formats listed above. The code will open the report within Access and make it visible.

AccessObjectExists is a function that I wrote to determine if the passed in object exists. You can clean that out.

Code:
Enum opgRptType
    XLS = 1
    RTF = 2
    SNAPSHOT = 3
    HTML = 4
End Enum

Public Function ExportReportToFile(strReportName As String, Optional lngRptType As opgRptType, Optional bolOpen As Boolean = False) As Boolean
    Dim strReportPath As String
    strReportPath = App.Path & "\"
    If Not (appAccess Is Nothing) Then
        If AccessObjectExists("Report", strReportName) Then
            With appAccess
            ' Output or display in specified format.
                Select Case lngRptType
                    Case XLS
                        .DoCmd.OutputTo acOutputReport, strReportName, acFormatXLS, _
                            strReportPath & strReportName & ".xls", bolOpen
                    Case RTF
                        .DoCmd.OutputTo acOutputReport, strReportName, acFormatRTF, _
                            strReportPath & strReportName & ".rtf", bolOpen
                    Case SNAPSHOT
                        ' Snapshot Viewer must be installed to view snapshot
                        ' output.
                        .DoCmd.OutputTo acOutputReport, strReportName, acFormatSNP, _
                            strReportPath & strReportName & ".snp", bolOpen
                    Case HTML
                        .DoCmd.OutputTo acOutputReport, strReportName, acFormatHTML, _
                            strReportPath & strReportName & ".htm", bolOpen
                    Case Else
                        .Visible = True
                        .DoCmd.OpenReport strReportName, acViewPreview
                End Select
            End With
            
            ExportReportToFile = True
        Else
            MsgBox strReportName & " could not be found.  Please check your database for the report.", vbExclamation & vbOKOnly, "ExportReportToSnap Failure"
            ExportReportToFile = False
        End If
    Else
        ExportReportToFile = False
    End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top