Originally Posted by
Gicu
No worries, nothing wrong
, I was just sure I answered something similar recently ...
Cheers,
I guess one last question I have is, is it possible to alter the criteria line so that it isn't directly calling out the specific form? That way if I use this code in other forms, I don't have to change this line. For instance, I used the below code with the alteration in the criteria but I'm getting an 3464 error on the DocCmd.OpenReport line....I'm assuming due to the criteria. I'm not sure what
Code:
Private Sub btnExportReport_Click()
Dim reportName As String
Dim criteria As String
Dim fd As Object
Dim filename As String
reportName = "rptComplaintLog"
criteria = "[ComplaintNumber]='" & Nz(Me.[ComplaintNumber], 0) & "'"
Set fd = Application.FileDialog(2)
filename = Me.CustomerLastName & ", " & Me.CustomerFirstName & " " & Format(Me.ComplaintDate, "m.d.yyyy") & ".rtf"
With fd
.Title = "Save to RTF"
.InitialFileName = "F:\Documents\" & filename
If .Show = -1 Then
filename = fd.SelectedItems(1)
If InStr(filename, ".") = 0 Then
filename = filename & ".rtf"
ElseIf Right(filename, 4) <> ".rtf" Then
k = InStrRev(filename, ".") - 1
filename = Left(filename, k)
filename = filename & ".rtf"
End If
DoCmd.OpenReport reportName, acViewPreview, , criteria, acHidden
DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, filename
DoCmd.Close acReport, reportName, acSaveNo
End If
End With
Set fd = Nothing
End Sub