Renaming a txt file with datetime stamp .

I’m scheduling a report using BCA which generates a txt file . Report is scheduled daily & BCA overwrite a earlier txt file . I want to preserve the earlier file .I’ve to rename the earlier file with a datetime stamp . How this is possible ? Do i’ve to write any script ? Thanks i advance


niranjan_d (BOB member since 2003-11-21)

Yes, you can do this by creating a VBA script and at the running of this script when you schedule the report.

Here is a possible way of doing it.

In VBA add a new Module and paste the script below.

When you run this macro all the reports will be exported with an extension like C:\Temp\ReportName-x-mm-yyyy.txt
Where x is the name of the report.


Sub export()

Dim reps As Reports
Dim Location As String
Dim FileName As String
Dim month As String

Set reps = ThisDocument.Reports

Location = “C:\Temp”
FileName = “ReportName”

If DatePart(“m”, Date) < 10 Then
month = 0 & DatePart(“m”, Date)
Else
month = DatePart(“m”, Date)
End If

For i = 1 To reps.Count

rep.exportAsText (Location & FileName & rep.name & “-” & month & “-” & DatePart(“yyyy”, Date) & “.txt”)

Next i

End Sub


Mister_E :belgium: (BOB member since 2004-07-05)

You can do it in DOS too, if you aren’t comfortable/happy with using VBA.