I inherited this DB and I am trying to learn more about it. Below is code in a command button which exports a report. When pressed, the intent is that it opens up a dialog box to allow the user to change the preset folder or file name. I have a good idea of what all the code means, except the portion in red. Would anyone mind explaining what this code is doing/intended for?
Code:
Private Sub btnExportReport_Click()
On Error GoTo btnExportReport_Click_Err
Dim ReportName As String
Dim fd As Object
Dim filename As String
Dim strReportName As String
strReportName = Reports(currentreport).Name
Set fd = Application.FileDialog(2)
filename = "Report" & " " & Format(Date, "mm.dd.yyyy") & ".pdf"
With fd
.Title = "Save to PDF"
.InitialFileName = "\Documents\" & filename
If .Show = -1 Then
filename = fd.SelectedItems(1)
If InStr(filename, ".") = 0 Then
filename = filename & ".pdf"
ElseIf Right(filename, 4) <> ".pdf" Then
k = InStrRev(filename, ".") - 1
filename = Left(filename, k)
filename = filename & ".pdf"
End If
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, filename
MsgBox "Report saved to " & filename
End If
End With
btnExportReport_Click_Exit:
Set fd = Nothing
Exit Sub
btnExportReport_Click_Err:
MsgBox "Error #" & Err.Number & " - " & Err.Description, , "Error"
Resume btnExportReport_Click_Exit
End Sub