[AccessD] A Matter of Killing

Jurgen Welz jwelz at hotmail.com
Mon Aug 17 11:58:08 CDT 2009


Our users are advised not to use their desktops for file storage on our network as these folders are not backed up.  For that reason I've found it best to create the save path on the fly.  Generally the path will be based on the user name, a table name and PK or some other determinate string.  When users accidentally drag entire folder trees to different locations you need to create the full path to guarantee it exists.

 

I generally create files of the same type with names that have an incrementing version suffix or a date stamp in the name except in those cases where it is important that there is only one file.  An example would be an invoicing workbook with a sheet added each month for invoices issued that month.  Multiple revisions of an invoice document would get a name with a claim number suffix followed by a hyphen and then a two digit version number suffix.  Since the path is determinate, I give users a button to open a folder for files related to the user or record and they can deal with the names beyond what the system provides.  Prior to killing a file, I generally try to open it exclusive or rename it to a name that you verify doesn't exist.  If renaming or opening exclusive fails you will get an error along the lines of trying to delete a file that is open anyway so this approach doesn't get you much further in the error handling department.  You'd be suprised how often the user himelf has a file open when he tries to delete it.  After verifying the file is there and not open, the file goes to the recycle bin.

 

Public Declare Function SHFileOperationA Lib "shell32.dll" (lpFileOp As FileOpStruct) As Long


'structure for the call to the Recycle operation

Private Type FileOpStruct
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgressTitle As String
End Type


'strFileName is the full path and name

Public Function Recycle(strFileName As String) As Boolean
    Dim Killed As FileOpStruct

 

    If Len(Dir(strFileName)) Then
        With Killed
            .wFunc = 3
            .pFrom = strFileName & vbNullChar
            .fFlags = 80
        End With
        Recycle = SHFileOperationA(Killed) = 0
    End If
End Function


Public Function fnFileIsOpen(ByVal strFileName As String) As Boolean
    On Error GoTo ErrorHandler

    Dim intFileHandle As Integer

 

    intFileHandle = FreeFile()
    Open strFileName For Input Lock Read As intFileHandle
    fnFileIsOpen = False

ExitRoutine:
    On Error Resume Next
    Close intFileHandle
    Exit Function
ErrorHandler:
    fnFileIsOpen = True
    Resume ExitRoutine
End Function


Ciao

Jürgen Welz

Edmonton, Alberta

jwelz at hotmail.com


 
> From: rockysmolin at bchacc.com
> To: accessd at databaseadvisors.com
> Date: Sun, 16 Aug 2009 15:09:48 -0700
> Subject: Re: [AccessD] A Matter of Killing
> 
> Into the library it goes! Desktop is never easy to find.
> 
> Rocky
> 
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
> Sent: Sunday, August 16, 2009 3:02 PM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] A Matter of Killing
> 
> On 16 Aug 2009 at 14:26, Rocky Smolin wrote:
> 
> > I could get around even that possibility by changing gstrBackEndPath 
> > to gstrFrontEndPath - another handy global I keep around for just such 
> > application. I'll have to ask the user what they prefer. User's in 
> > Bahrain, BTW - another 'remote' location.


_________________________________________________________________
Stay on top of things, check email from other accounts!
http://go.microsoft.com/?linkid=9671355


More information about the AccessD mailing list