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!

Code for Exporting Report

Status
Not open for further replies.
Jul 4, 2004
42
0
0
GB
Hi.

I use the following code on a command button to run reports which are selected from a populated list box. The code "me.preview.Value" selects whether the report is printed or previewed if a value is put in a tickbox called preview.

Private Sub butRunReport_Click()
On Error GoTo butRunReport_ClickErr
If Not IsNull(Me.Reports) Then
DoCmd.OpenReport Me.Reports, IIf(Me.Preview.Value, acViewPreview, acViewNormal)
End If
Exit Sub
butRunReport_ClickErr:
Select Case Err.Number
Case 2501
MsgBox "Report cancelled, or no matching data.", vbInformation, "Information"
Case Else
MsgBox "Error " & Err & ": " & Error$, vbInformation, "cmdOpenReport_Click()"
End Select
Resume Next
End Sub


I require help with the code where a file is not printed or previewed but exported to .rtf if another tickbox returns a value.

Thanks in advance for your help..
 
To make it easier in the coding, you could have a compbo box next the the combo box of the report, stating Preview, Print or Export.

Then use a select case to determine what action is taken.

So lets say the combo box is called cmbAction
Code:
Select case cmbAction

Case "Preview"

 DoCmd.OpenReport Me.Reports, acViewPreview

Case "Print"

 DoCmd.OpenReport Me.Reports, acViewNormal

Case "Export"

    Dim FilePathName

    FilePathName= InputBox("Export Path", "Export Path")


    DoCmd.OutputTo acOutputReport, Me.Reports, acFormatRTF, FilePathName & ".rft", False 'or you could change this to .doc instead, works the same


End Select

Hope this helps, if not let me know, and i will change my idea to help better...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top