Results 1 to 6 of 6
  1. #1
    cgschlangen
    Guest

    Deleting External Files w/ Command Button (Access 2000)

    Is there a way to delete an external file whose value is in a field in my table along w/ deleting the record?

    Here's a more in depth explanation:
    I have a database that I'm using to manage a very large amount of sound files for work. A user will have the ability to delete an individual record, or many records when they are no longer needed, but I would also like to make an automated proccess that will save the user the trouble of having to delete in the database, and then open explorer and browse to the proper folder to delete records from there also...

    Any suggestions?
    Thanks, Dan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Deleting External Files w/ Command Button (Access 2000)

    You could handle this in the After Del Confirm event of the form (this requires that you get prompted for confirmation if you delete a record):

    Private Sub Form_AfterDelConfirm(Status As Integer)
    If Status = acDeleteOK Then
    Kill Me.SoundFileName
    End If
    End Sub

    where SoundFileName is the name of the field containing the path and file name of the sound file. If ou keep the path in another field, you must concatenate the path and file names.

  3. #3
    cgschlangen
    Guest

    Re: Deleting External Files w/ Command Button (Access 2000)

    Would this work with a delete query?

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Deleting External Files w/ Command Button (Access 2000)

    No it wouldn't.
    If it helps, you can use the wildcard with the Kill statement that Hans has suggested.

  5. #5
    New Lounger
    Join Date
    Jun 2003
    Location
    Melbourne, Victoria, Australia
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deleting External Files w/ Command Button (Access 2000)

    If you were to create a Select Query with the exact same criteria as your Delete Query, you could run the following code from a command button on a form:

    Private Sub cmd_Del_Files_Click()
    On Error GoTo Error_Handler

    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset

    Set dbs = Application.CurrentDb
    Set rst = dbs.OpenRecordset("qrySelectRecords")

    rst.MoveFirst

    Do Until rst.EOF
    Kill rst.Fields("SoundFileName")
    rst.MoveNext
    Loop

    DoCmd.OpenQuery "qryDeleteRecords"

    rst.Close
    dbs.Close


    Error_Exit:
    Exit Sub

    Error_Handler:
    MsgBox "Err No: " & Err.Number & "; " & Err.Description
    Resume Error_Exit

    End Sub


    This code would iterate thru each record in the Select Query, delete the file specified in the field named "SoundFileName" (which would have the full path and filename) as Hans previously stated, and then run your Delete Query to remove the records.

    I've tested this code briefly, but maybe Hans or someone could cast an eye over it as I'm a little new to this stuff.

    Hope this helps,

    Cheers,

    Paul

  6. #6
    cgschlangen
    Guest

    Re: Deleting External Files w/ Command Button (Access 2000)

    That works like a dream!
    Thanks Hans for the Form Deletion command - and thank you Paul for the Query Code!
    I love this place!!!! lol
    <img src=/S/cloud9.gif border=0 alt=cloud9 width=25 height=23>
    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •