VBA Move File

So you need to end off a procedure by moving a file?
This video shows you how to use the FileSystemObject
and vba to move a file out of one directory into another?

Well, this video shows you how to do it…

Option Compare Database

'ERIK LOEBL(713)409-7041
'EMAIL: erik@loeblcomservices.com
'WEB:   http://loeblcomservices.com

Private Sub btnCreateTable_Click()
    Dim strFileName As String
    strFileName = "rptAddresses"

    DoCmd.OutputTo acOutputReport, strFileName, acFormatPDF, CurrentProject.Path & "\" & strFileName & ".pdf"
    'move file to sent directory
    move_file strFileName
End Sub

Sub move_file(filename)

    Dim objFSO As Object
    'Dim objFSO As FileSystemObject


    Dim strFromFile As String
    Dim strToFile As String

    strFromFile = CurrentProject.Path & "\" & filename & ".pdf"
    'Your folder needs to be called "complete"
    strToFile = CurrentProject.Path & "\complete\" & filename & ".pdf"
    'late binding
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'early binding - need library reference to "Microsoft Scripting Runtime"
    'Set objFSO = New FileSystemObject
    objFSO.MoveFile strFromFile, strToFile
    MsgBox "The folder is moved from " & strFromFile & " to " & strToFile

End Sub


Click here for the database and the code:

Offsite Related Information:

“Go Fund Me” Page

($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Tags: , , , , ,