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

Recommended Answers

All 6 Replies

its not about date but your pathName is wrong.
should be : C:\

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
Else
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"
Else
    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
commented: Nice +1
commented: Great +1
commented: Nice one friend :) +1

thanks
and sorry i misunderstood something thats why the mistake

Don't mind it Friend :)
Happy coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.