Error 75 (1 Viewer)

habiler

Registered User.
Local time
Tomorrow, 00:32
Joined
Aug 10, 2014
Messages
70
My code hangs (Error75) if the folder exists. How to go next

Code:
Option Compare Database
Option Explicit

Sub Verifier_Presence_Sous_Dossier()
    Dim Pth As String
    Dim i As Integer
    Dim strSql As String
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim fs As FileSystemObject
    Dim mySource As Object
    Dim Folder As Variant
    Dim fso As Object
    Set dbs = CurrentDb
    Dim Root1 As String, Root2 As String, Root3 As String
    Dim NewName As String
    Dim varFldrsRoot1 As Variant
    
    Set dbs = CurrentDb
    strSql = "SELECT DEC.Matr, DEC.NomName, DEC.NomNameMatr, DEC.NomNameMatrk, DEC.Languagecode FROM [DEC] WHERE (((DEC.Languagecode)=1) AND ((DEC.[Matr])= 4810));" 'Or (DEC.[Matr])=105185 Or (DEC.[Matr])=5363));"
    Set rst = dbs.OpenRecordset(strSql, dbOpenSnapshot, dbFailOnError)
    
    Pth = "F:\Pers\"  'Path to the top folder with trailing slash
  
    
    Root1 = Pth & rst!NomName
    Root2 = Root1 & "\" & "A. Pièces officielles recrutement"
    'Root3 = Root1 & "B. Promotions"

    If Len(Dir(Root1, vbDirectory)) = 0 Then

        MkDir Root1

    End If

    If Len(Dir(Root2, vbDirectory)) = 0 Then

        MkDir Root2

    End If
  
    varFldrsRoot1 = Split("1. P1,2. Recueil de travail,3. Autre,4. Contrats,5. Avenants", ",")

    For i = 0 To UBound(varFldrsRoot1)

        If Len(Dir(Root2 & varFldrsRoot1(i), vbDirectory)) = 0 Then

        MkDir Root2 & "\" & varFldrsRoot1(i)
          Else
          Exit For
        End If
     Next i
        'End If

            
 
 
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:32
Joined
Sep 21, 2011
Messages
14,317
Test to see if it exists first?
 

Users who are viewing this thread

Top Bottom