Option Compare Database
' Delete File
Option Explicit
Sub Main()
Dim oFSO
Dim sSourceFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
sSourceFile = "C:\SourceFile.txt" ' Check if file exists to prevent error
If oFSO.FileExists(sSourceFile) Then
oFSO.DeleteFile sSourceFile
End If ' Clean Up
Set oFSO = Nothing
End Function
Private Sub Command4_Click()
On Error GoTo Err_cmdTest_Click
'Must 1st set a Reference to the Microsoft Office XX.X Object Library
Dim dlgOpen As FileDialog
Dim strExportPath As String
Const conOBJECT_TO_EXPORT As String = "qryExportMetrics"
Set dlgOpen = Application.FileDialog(msoFileDialogFolderPicker)
With dlgOpen
.ButtonName = "Export To"
.InitialView = msoFileDialogViewLargeIcons
.InitialFileName = CurrentProject.Path
If .Show = -1 Then
'Allow for Root Directory selection: C:\, D:\, etc.
strExportPath = Replace(.SelectedItems(1) & "\", "\\", "\")
Call DoCmd.TransferSpreadsheet(TransferType:=acExport, _
TableName:=conOBJECT_TO_EXPORT, _
FileName:=strExportPath & conOBJECT_TO_EXPORT & ".xls")
Call DoCmd.TransferSpreadsheet(TransferType:=acExport, _
TableName:="qryCapacityBuilding", _
FileName:=strExportPath & conOBJECT_TO_EXPORT & ".xls")
MsgBox "[" & conOBJECT_TO_EXPORT & "] has been Exported to " & strExportPath & _
conOBJECT_TO_EXPORT & ".xls", vbInformation, "Export Complete"
End If
End With
'Set the Object Variable to Nothing.
Set dlgOpen = Nothing
DoCmd.Close
Exit_cmdTest_Click:
Exit Sub
Err_cmdTest_Click:
MsgBox Err.Description, vbExclamation, "Error in cmdTest_Click()"
Resume Exit_cmdTest_Click
End Sub