I have code that is supposed to make a file path (on the local drive) and put a file there. The code checks to see if the file path exists and if it doesn't, it creates it and then dumps the file there (excel format via transfer spreadsheet)..
The next time they run the program, the part of the code that checks to see if the file is there will run and show that it exists. So, I would like to blow it away and then make the directory again and then dump the file. To do this, the ELSE, kills all (old) files there and then is supposed to remove the directory and then re-create it and then dump the new file there.
1. The program runs the first bit, saving the file to the drive. But when run a second time, it does delete the file (via KILL), but balks at the next bit of code where it is supposed to delete the just created file path. I get a run time error 75: path/file access error.
I do not have the file path open in explorer and to make things more strange, if I do open explorer and try to delete the folder, it tells there is a sharing error. BUT! if I close Access, THEN I can delete the folder through Explorer. Its almost as if Access is making the PC think that the folder is open and so cannot do any modificatgions until Access is closed..
Is this an issue with Access or with my OS? Does anyone know any workarounds? It doesn't seem to be an issue with the code..
2. What code can i use to check to see if a file exists already (see below - code would need to go right after the ELSE statement as an IF to check to see if file exists before performing the KILL)?
Here is the code:
Dim str_fp As String
Dim str_fp_kill As String
Dim str_fn As String
str_fp = "c:\temp\pr\"
str_fp_kill = "c:\temp\pr\*"
str_fn = str_obj_name_tbl & "_pr.xls"
If Dir(str_fp, vbDirectory) = "" Then
MkDir (str_fp)
Else
Kill (str_fp_kill) 'need to check to see if file exists..
RmDir (str_fp)
'MkDir (str_fp)
End If
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, str_obj_name_tbl, str_fp & str_fn, True
The next time they run the program, the part of the code that checks to see if the file is there will run and show that it exists. So, I would like to blow it away and then make the directory again and then dump the file. To do this, the ELSE, kills all (old) files there and then is supposed to remove the directory and then re-create it and then dump the new file there.
1. The program runs the first bit, saving the file to the drive. But when run a second time, it does delete the file (via KILL), but balks at the next bit of code where it is supposed to delete the just created file path. I get a run time error 75: path/file access error.
I do not have the file path open in explorer and to make things more strange, if I do open explorer and try to delete the folder, it tells there is a sharing error. BUT! if I close Access, THEN I can delete the folder through Explorer. Its almost as if Access is making the PC think that the folder is open and so cannot do any modificatgions until Access is closed..
Is this an issue with Access or with my OS? Does anyone know any workarounds? It doesn't seem to be an issue with the code..
2. What code can i use to check to see if a file exists already (see below - code would need to go right after the ELSE statement as an IF to check to see if file exists before performing the KILL)?
Here is the code:
Dim str_fp As String
Dim str_fp_kill As String
Dim str_fn As String
str_fp = "c:\temp\pr\"
str_fp_kill = "c:\temp\pr\*"
str_fn = str_obj_name_tbl & "_pr.xls"
If Dir(str_fp, vbDirectory) = "" Then
MkDir (str_fp)
Else
Kill (str_fp_kill) 'need to check to see if file exists..
RmDir (str_fp)
'MkDir (str_fp)
End If
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, str_obj_name_tbl, str_fp & str_fn, True