FredixBlog


Just my log about anything I could find enjoyable.



Copy a file

author Posted by: fredometro on date Jan 1st, 2004 | filed Filed under: MS-Access

This function copies a file


Const FOF_NOCONFIRMMKDIR = &H200
Const FOF_FILESONLY = &H80

Private Type SHFILEOPSTRUCT
      hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgress As String
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" _
    Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Public Function MyFileCopy(txtSource, txtDestination)
Dim lFileOp As Long
Dim lresult As Long
Dim lFlags As Long
Dim SHFileOp As SHFILEOPSTRUCT
Dim chkSilent, chkYesToAll, chkRename, chkDir, chkFilesOnly As Boolean

DoCmd.Hourglass True

lFileOp = FO_COPY

chkYesToAll = True
chkSilent = True

If chkSilent Then lFlags = lFlags Or FOF_SILENT
If chkYesToAll Then lFlags = lFlags Or FOF_NOCONFIRMATION
If chkRename Then lFlags = lFlags Or FOF_RENAMEONCOLLISION
If chkDir Then lFlags = lFlags Or FOF_NOCONFIRMMKDIR
If chkFilesOnly Then lFlags = lFlags Or FOF_FILESONLY
'
' NOTE: By adding the FOF_ALLOWUNDO flag you can move
' a file to the Recycle Bin instead of deleting it.
'
With SHFileOp
    .wFunc = lFileOp
    .pFrom = txtSource & vbNullChar & vbNullChar
    .pTo = txtDestination & vbNullChar & vbNullChar
    .fFlags = lFlags
End With
lresult = SHFileOperation(SHFileOp)
'
' If User hit Cancel button while operation is in progress,
' the fAborted parameter will be true
'
DoCmd.Hourglass False
'If lresult <> 0 Or SHFileOp.fAborted Then Exit Function
'MsgBox "Operation Complete", vbInformation, "File Operations"
MyFileCopy = lresult
End Function

No related posts.

     Add A Comment

You must be logged in to post a comment.


Warning: include(/home/www/web421/html/phpTraffic/write_logs.php) [function.include]: failed to open stream: No such file or directory in /home/websitef/public_html/fredometro.com/wp-content/themes/blueshadow/footer.php on line 15

Warning: include() [function.include]: Failed opening '/home/www/web421/html/phpTraffic/write_logs.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/websitef/public_html/fredometro.com/wp-content/themes/blueshadow/footer.php on line 15