ddimokas
ddimokas

Reputation: 1

Create a directory for every new contact in ms-access and check the existence only with the ID of the contact

I would like to create a new directory for any new contact I enter in an access database but I would like to check the existence of the directory only with the last 4 characters. These last 4 characters are the ID of the contact, so in case someone change the details of the contact (like the name) the form will not create a new directory. For this reason with a field "TxtContactAs" I calculate the name of the directory to something like "John Doe - 0085"

My code is:

Private Sub MakeContactFolder()
    
    Dim Path As String
    
    Path = Application.CurrentProject.Path & "\" & Me.TxtCustOrSupp.Value
    If Dir(Path, vbDirectory) = vdNullString Then MkDir (Path)
    
    Path = Application.CurrentProject.Path & "\" & Me.TxtCustOrSupp.Value & "\" & Me.TxtContactAs.Value
    If Right(Dir(Path, vbDirectory), 4) <> Right(Me.TxtContactAs.Value, 4) Then MkDir (Path)
    
End Sub

The problem is that it doesn't give me an error but every time I change the details of the contact the form creates a new directory with the new name.

Upvotes: 0

Views: 42

Answers (0)

Related Questions