Function FileExport(exportqry As Variant)
Dim dlgPath As FileDialog
Dim filesavepath As Variant
Dim completed As Variant
Dim fullfile As Variant
Dim filenamedate As String
Dim fs As Object
On Error GoTo Error_FileExport
Set dlgPath = Application.FileDialog(msoFileDialogFolderPicker)
With dlgPath
.Show
For Each filesavepath In .SelectedItems
Next
End With
Set fs = CreateObject("Scripting.FileSystemObject")
filenamedate = DatePart("y", Now()) & DatePart("h", Now()) & DatePart("n", Now())
fullfile = filesavepath & "BBP" & filenamedate & ".xls"
With fs
If .FileExists(fullfile) = True Then
.deletefile fullfile
Else
End If
End With
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, exportqry, fullfile
completed = "The export has completed. The file is " & fullfile & "."
MsgBox completed, vbDefaultButton1, "Export Complete"
Forms!Menu.SetFocus
Exit_FileExport:
DoCmd.Close acForm, "Export"
Exit Function
Error_FileExport:
If Err.Number <> 2450 Then
MsgBox "Error number " & Err.Number & ": " & Err.Description
Else
End If
DoCmd.Close acForm, "Export"
Exit Function
End Function