Gustav Brock
Gustav at cactus.dk
Sun Aug 16 12:52:27 CDT 2009
Hi Rocky
Here's how to perform this simple task which has a twist. Problem is that Kill sometimes cannot delete the file because of write protection or missing rights or a file lock:
<code>
Public Function KillFile(ByVal strFile As String) As Boolean
Dim booSuccess As Boolean
' Delete the file named strFile if it exists.
On Error GoTo Exit_KillFile
If Len(Dir(strFile, vbNormal)) = 0 Then
' The file is not there.
booSuccess = True
Else
Kill strFile
' Check if the file was deleted.
If Len(Dir(strFile, vbNormal)) = 0 Then
' The file was deleted.
booSuccess = True
End If
End If
Exit_KillFile:
KillFile = booSuccess
End Function
</code>
So:
strFile = gstrBackEndPath & Forms!frmBFGExportBOM!txtAssemblyPartNumber & " - BOM Export.XLS"
If KillFile(strFile) Then
' Run export routine.
Else
' Display error.
MsgBox "Cannot currently export to file " & strFile & "."
End If
/gustav
>>> rockysmolin at bchacc.com 16-08-2009 15:56 >>>
Dear List:
I am exporting a bill of materials to a spreadsheet from an access database.
The file name on the spreadsheet is the part number the user selects plus
some other stuff.
Before I create it I issue a Kill:
Kill gstrBackEndPath & Forms!frmBFGExportBOM!txtAssemblyPartNumber & " - BOM Export.XLS"
If the file is not there it generates an error of course, file not found.
Is there anything wrong with the simple workaround:
On Error Resume Next
Kill gstrBackEndPath & Forms!frmBFGExportBOM!txtAssemblyPartNumber & " - BOM Export.XLS"
On Error GoTo 0
MTIA,
Rocky Smolin
Beach Access Software
858-259-4334
www.e-z-mrp.com <http://www.e-z-mrp.com/>
www.bchacc.com <http://www.bchacc.com/>