mkdir code not working please help!

Sketchin

Registered User.
Local time
Yesterday, 16:11
Joined
Dec 20, 2011
Messages
577
I have this bit of code

Code:
If Dir("R:\Database Tables\Database Dashboard History\" & Date, vbDirectory) = "" Then
       MkDir ("R:\Database Tables\Database Dashboard History\" & Date)
    Else

that gives me a path not found error. I know the path exists and have modified it to a simple c:\Testing path just to see if that was the problem and I get the same error. In the end, I would like it to create a directory in that path with the current date as the folder name.

Thanks
 
Last edited:
You probably would need to format the date as it would normally put in full stops and that is why it wont allow you to create the folder.

Format(Date,"dd mmm yyyy") would work

If it doesn't work then you might need to reveal more of your code and let us know where it stops.
 
You can't just use DATE because folders can't have the slashes in the path. So, if you use the dd/mm/yyyy format do that:

Code:
If Dir("R:\Database Tables\Database Dashboard History\" & Format(Date, "dd-mm-yyyy"), vbDirectory) = "" Then
       MkDir ("R:\Database Tables\Database Dashboard History\" & Format(Date, "dd-mm-yyyy"))
    Else

or maybe for format of "ddmmyyyy" without characters.
 
That fixed that problem, but now I have a new one
Code:
Private Sub Command5_Click()
Dim MyFilename As String
Dim MyPath As String
If Dir("R:\Database Tables\Database Dashboard History\" & Format(Date, "dd mmm yyyy"), vbDirectory) = "" Then
MkDir ("R:\Database Tables\Database Dashboard History\" & Format(Date, "dd mmm yyyy"))
 
End If
MyFilename = Format(Date, "yyyy") & "-" & _
Format(Date, "mm") & "-" & Format(Date, "dd") & "-" & Format(Time, "HH:MM") & _
"-Dashboard Snapshot" & ".pdf"
MyPath = "R:\Database Tables\Database Dashboard History\" & Format(Date, "dd mmm yyyy") & "\"
DoCmd.OutputTo acOutputReport, "rptDashboardSnapshot", acFormatPDF, MyPath & MyFilename, False
End Sub

It fails on the last line saying "OutputTo action was cancelled"

Ideas?
 
Your file name is using characters you can't use in a file path. The colon:

Format(Time, "HH:MM")
Change to

HHMM

instead
 
You could reduce the code by using Now() rather than Date and then it is a single format in the way you want and as Bob has pointed out you can't use : in the file name.
 

Users who are viewing this thread

Back
Top Bottom