[AccessD] A Matter of Killing

Rocky Smolin rockysmolin at bchacc.com
Sun Aug 16 13:25:55 CDT 2009


Gustav:

It may be overkill (no pun intended) for this particular problem - custom
feature for one fairly technically competent user - but it's the right thing
for the general purpose program like my manufacturing system.

Thanks

Rocky


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Sunday, August 16, 2009 10:52 AM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] A Matter of Killing

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/> 



--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list