Saving Report with Report Date in Name

Not sure if anyone is interested, but I wrote the following code, so that when you save a report to PDF, Excel, etc, you get a report Name like

Weekly Department Item Summary from 3-10-2019 to 3-16-2019.pdf

Just thought someone might be trying to do the same thing.

I suggested to FastReports that they add pre and post parameters, so you could pass a Save to Directory, and a Date or Department name into the FileName.

This is working well for me, so far.

Dim rptdir, outdir, mdate, mDate2 As String
Dim FileToCopy, NewCopy As String
Dim FReport As FastReport.Report
Me.Hide()
rptdir = SysInfo.GlbRptDir
outdir = SysInfo.GlbOutDir

FileToCopy = rptdir.ToString & "WeeklyDepartmentItemSummary.frx"
mdate = mToDateStr.Replace("/", "-")
mdate2 = mFromDateStr.Replace("/", "-")
NewCopy = outdir.ToString & "Weekly Department Item Summary from " & mDate2 & " to " & mdate & ".frx"

If System.IO.File.Exists(FileToCopy) = True Then
System.IO.File.Copy(FileToCopy, NewCopy)
End If

Me.Hide()

FReport = New FastReport.Report
Dim reportName As String = NewCopy
FReport.Load(reportName)
FReport.RegisterData(dsWeekDeptItemSummary)
FReport.SetParameterValue("prmConn", SysInfo.GlbConnString)
FReport.SetParameterValue("prmStoreNumber", SysInfo.GlbStoreNumber)
FReport.SetParameterValue("prmFromDate", mFromDateStr)
FReport.SetParameterValue("prmToDate", mToDateStr)
FReport.Prepare()
FReport.ShowPrepared()
Me.Show()
System.IO.File.Delete(NewCopy)


Bill Sutton

Comments

  • Thanks Bill this is a nice feature and I appreciate you sharing your code.

    While a NOOB I'm going to try and write this in C# and post my results as well. Stay tuned.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.