Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

test for existence of a directory 1

Status
Not open for further replies.

Zepher2

Technical User
Dec 29, 2001
25
US
I am teying to test to see if a directory and sub directory exists on my C drive and if it does not then create the directory using the variable Me.FileNo as the name.

The Mkdir function works and the directory is created as expected when I run the the procedure the first time. The problem is the second time I run the procedure it tries to create a duplicate director and I get a run time error. So I must have something wrong with the If then statement. Can anone help me. I am a beginner with VBA.

Here is the code:

Private Sub CmdMakeDir_Click()

If Dir("C:\Client Data" & "\" & Me.[FileNo]) = "" Then

MkDir "C:\Client Data" & "\" & Me.[FileNo]

End If
End Sub
 
Just ignore the error when creating.
On error resume next
MkDir "C:\Client Data"
MkDir "C:\Client Data" & "\" & Me.[FileNo]
On Error goto 0
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
That did the trick. Thank you for your help.
 
Use option vbDirectory for checking of directory existence:

If Dir("C:\Client Data\" & Me.FileNo, vbDirectory) = "" Then
MkDir "C:\Client Data\" & me.FileNo
End If


Now error will not proceed.

Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top