I have an access 2007 Database that outputs a report in excel format, the report is dependent on a date parameter that is chosen by the user. This parameter is selected via a textbox (text100) that has a pop up calendar. I would like to use the date in the text box(text100) as part of the filename. I am using the transferspreadsheet method to create the export, However I do not need the column headers. Once the file is created I have the code open the file and delete the headers. Also the current code is using todays date in the filename which is not accurate. The filename needs to reflect the date that was selected by the user in the text box from the pop up calendar
Ok here is the code.
Sub Branch298nohdr()
Dim Filename As String
Dim Path As String
Dim Branch As Integer
Dim Text100 As Date
Dim xl
Branch = "298"
Path = "Path" & Branch & "\"
Filename = "Identity Report " & Branch & " " & _
Replace(Text100, ":", " ") & ".xls"
If Dir(Path & Filename) <> "" Then
MsgBox "File has been created already"
If Dir(Path & Filename) <> "" Then
GoTo 53
End If
Else
Set xl = CreateObject("excel.application")
TempVars.Add "branchnum", Branch
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, _
"queryname", Path & Filename, False
xl.workbooks.Open Path & Filename
With xl
.Rows("1:1").entirerow.Delete
.Columns("L:L").select
.Selection.NumberFormat = "0"
.range("a1").select
xl.workbooks(1).Close Savechanges:=True
xl.Quit
Set xl = Nothing
53
MsgBox "Done!"
End With
TempVars.Remove "branchnum"
End If
Branch298nohdr_Exit:
Exit Sub
End Sub
Text 100 is where the user selects a date via a pop up calendar. I would like to use this date as part of the file name. Currently using the text100 as part of the filename it is being referenced as 12:00 am, and then adds this to the file name. I hope this clears up my intention.
Text 100 gets set on the opening form then there are several buttons which allow the user to pick between several branches or all branches.