I have a macro that is schedule to run every day to copy a database. However, when I execute the macro it does not allow me to close access. Access is open to execute the macro but would like to close it automatically (as part of this macro). I added a QUIT macro but give me an error. Does any can help me to complete this macro and be able to close Access. The code is below.
Thank you for guidance and collaboration.
Luis
Function CopyITPlanningDatabase()
' Using the Scripting.FileSystemObject to copy files
' Requires a reference to Microsoft Scripting Runtime Library
' In any code window Menu > Tools > References
' Microsoft Scripting Runtime Library - Checked
Dim strSourceFile As String
Dim strDestinationPath As String
Dim objFso As Scripting.FileSystemObject
' Set the target file path
strSourceFile = "\\FTWSS02\BIGBUCKS\itplan-copy\itplan.mdb"
' Set the target file path
strDestinationPath = "\\ftwgroups\jsf\jsfitcoord\acWKspace\F-35 Dash Board\"
' Instantiate instance of Scripting file system object
Set objFso = New Scripting.FileSystemObject
' Check that the source file exists
If objFso.FileExists(strSourceFile) Then
' Check that the destination folder exists.
If objFso.FolderExists(Mid(strDestinationPath, 1, InStrRev(strDestinationPath, "\", , vbTextCompare))) Then
' Copy the file, overwriting existing file of same name...
strDestinationPath = strDestinationPath & "LRitplan.mdb"
objFso.CopyFile strSourceFile, strDestinationPath, True
Else
' maybe use objFso.Buildpath to create the folder
' depends how bulletproof you want to make this.
End If
End If
DoEvents
' Destroy instantiated objects
Set objFso = Nothing
End Function
Thank you for guidance and collaboration.
Luis
Function CopyITPlanningDatabase()
' Using the Scripting.FileSystemObject to copy files
' Requires a reference to Microsoft Scripting Runtime Library
' In any code window Menu > Tools > References
' Microsoft Scripting Runtime Library - Checked
Dim strSourceFile As String
Dim strDestinationPath As String
Dim objFso As Scripting.FileSystemObject
' Set the target file path
strSourceFile = "\\FTWSS02\BIGBUCKS\itplan-copy\itplan.mdb"
' Set the target file path
strDestinationPath = "\\ftwgroups\jsf\jsfitcoord\acWKspace\F-35 Dash Board\"
' Instantiate instance of Scripting file system object
Set objFso = New Scripting.FileSystemObject
' Check that the source file exists
If objFso.FileExists(strSourceFile) Then
' Check that the destination folder exists.
If objFso.FolderExists(Mid(strDestinationPath, 1, InStrRev(strDestinationPath, "\", , vbTextCompare))) Then
' Copy the file, overwriting existing file of same name...
strDestinationPath = strDestinationPath & "LRitplan.mdb"
objFso.CopyFile strSourceFile, strDestinationPath, True
Else
' maybe use objFso.Buildpath to create the folder
' depends how bulletproof you want to make this.
End If
End If
DoEvents
' Destroy instantiated objects
Set objFso = Nothing
End Function