VBA‎ > ‎

VBA to check if a file folder exists and if not create it

We have a client who has a standard way of saving files for each of their clients on a shared network drive.   This VBA code calculates what the shared network drive should be called for each client in a database and then checks to see if that directory already exists on the shared network drive.  If it doesn't, it creates it.
Dim strFilelocation As String
strFilelocation = "\\servername\customer\"
'get customer
Dim strCustomerName As String
strCustomerName = DLookup("CompanyName", "Customer", "customerID=" & lngCustomerID)
strFilelocation = strFilelocation & strCustomerName
If Dir(strFilelocation, vbDirectory) = vbNullString Then
    MkDir strFilelocation
End If