Hi,
I'm have a macro that creates a folder with the date as the name, then runs all my queries and places the results in this folder.
What i'm trying to do is to check when the macro is run if the folder already exists, if it does then delete the folder and run the macro again.
Problem i'm having is it wont delete the file because it says it is in use, how do i stop it from being in use?
I'm have a macro that creates a folder with the date as the name, then runs all my queries and places the results in this folder.
What i'm trying to do is to check when the macro is run if the folder already exists, if it does then delete the folder and run the macro again.
Problem i'm having is it wont delete the file because it says it is in use, how do i stop it from being in use?
Code:
[FONT=Calibri][FONT=Calibri]dirname = "k:\daily exports\Export Tue-Fri AM\" & Format(Date - 1, "dd-mm-yyyy") & "\"[/FONT]
[FONT=Calibri]If Dir(dirname, vbDirectory) = "" Then[/FONT]
[FONT=Calibri]MkDir dirname 'create the date folder in the exports folder[/FONT]
[FONT=Calibri] DoCmd.OutputTo acOutputQuery, "Cleaning B", acFormatXLS, dirname & "Cleaning B " & Format(Date - 1, "dd-mm-yyyy") & ".xls", False, ""[/FONT]
[FONT=Calibri] DoCmd.OutputTo acOutputQuery, "Cleaning C", acFormatXLS, dirname & "Cleaning C " & Format(Date - 1, "dd-mm-yyyy") & ".xls", False, ""[/FONT]
[FONT=Calibri]MsgBox ("Reports have now been created and saved in - " & dirname), vbInformation, "Reports Saved"[/FONT]
[FONT=Calibri]Else[/FONT]
[FONT=Calibri]'MsgBox "The folder already exists..." & Chr(10) & "Please check the directories using Windows Explorer.", vbOKOnly[/FONT]
[FONT=Calibri]RmDir ("k:\daily exports\Export Tue-Fri AM\" & Format(Date - 1, "dd-mm-yyyy"))[/FONT]
[/FONT]