Access MVP (2010-2015)

oOo.oOo.oOo.oOo.oOo.oOo

Check if File exists

Sometimes you need to see if a file is in a directory for one reason or another…

Will delete the file if it exists

If FileExists(C:\Folder\Subfolder\YourDatabaseName.accdb) Then
     Kill "C:\Folder\Subfolder\YourDatabaseName.accdb"
Else
     Msgbox "Nothing to do!"
End if

Will rename the file if it exists

If FileExists("\\YourServerName\Folder\Subfolder\" & Me.cboYear & "-VendorReevaluation.xlsx") = True Then
     xlWBk.SaveAs "\\YourServerName\Folder\Subfolder\" & Me.cboYear & "-VendorReevaluation." & Format(Date, "mmddyyyy") & ".xlsx", 51
Else
     ApXL.DisplayAlerts = False
     xlWBk.SaveAs "\\YourServerName\Folder\Subfolder\" & Me.cboYear & "-VendorReevaluation.xlsx", 51
     ApXL.DisplayAlerts = True
End If

Loading

Comments are closed.