|
|

Deleting a File to the Recycle Bin
One of the more annoying things about the Kill statement in Access is that it deletes files permanently, bypassing the Recycle Bin. Often you may instead want to allow user-recovery of these files. Here is a way of doing this, using an API call. Copy and paste the code below into a new module, and you can then send files to the Recycle Bin:
Private Declare Function apiSHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type
Private Const FOF_ALLOWUNDO = &H40
Private Const FO_DELETE = &H3
Private Const FOF_NOCONFIRMATION = &H10
Sub sDelete(strFile As String)
Dim typSHFile As SHFILEOPSTRUCT
Dim lngReturn As Long
If Len(Dir(strFile)) = 0 Then
MsgBox "File does not exist.", vbOKOnly, " "
Else
With typSHFile
.pFrom = strFile & vbNullChar & vbNullChar
.wFunc = FO_DELETE
.fFlags = FOF_ALLOWUNDO Or FOF_NOCONFIRMATION
End With
lngReturn = apiSHFileOperation(typSHFile)
End If
End Sub
|
Top
HOME |
NEW |
TABLES |
QUERIES |
FORMS |
REPORTS |
GENERAL |
API |
DOWNLOADS |
TUTORIAL |
RESOURCES
E-MAIL
Copyright & Disclaimer
|
| |