1.Dim d As String

2.d = Format(Now(), "dddd, yyyy mmmm dd")

3. MsgBox (d)

4.If Dir("c:/", Photos & d) = "" Then

5.rspCreate = MsgBox("Directory doesn't exist, do you wish to create it?", vbYesNo)

6.If rspCreate = vbYes Then

7. MkDir "My Documents/swapna"

8. End If

i want to create a folder with name photo+currentdate
so i used the above code
but im getting the error type mismatch in line no 4
i want to convert the data variable to string

plz help

8 Years
Discussion Span
Last Post by Jx_Man

yes i tried still getting the error
i want to create a folder say photos27/05/2008 which is to be in c:
its not a folder inside folder photo
am i clear


Yes, i know it but your sintax is wrong, its should be C:\ not C:/
Also you don't have function to check if folder exist or not. see this following code :

Public Function FolderExist(Path As String) As Boolean

If LenB(Path) = 0 Then FolderExist = False: Exit Function

If LenB(Dir$(Path, vbDirectory)) > 0 Then
If (GetAttr(Path) And vbDirectory) = vbDirectory Then FolderExist = True
FolderExist = False
End If
End Function

Private Sub Command1_Click()
Dim d, Path As String

d = Format(Now(), "dddd, yyyy mmmm dd")
MsgBox (d)

Path = "C:\Photos " & d
If FolderExist(Path) = True Then
    MsgBox "Folder is available"
    rspCreate = MsgBox("Directory doesn't exist, do you wish to create it?", vbYesNo)
    If rspCreate = vbYes Then
        MkDir Path
    End If
End If
End Sub
Votes + Comments
Nice one friend :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.