On Tue, 17 Feb 1998 16:22:37 GMT in comp.databases.ms-access,
ara
...@galactica.it (Alberto Rausa) wrote:
>Can i copy a file from VBA and Access2?
Sub CopyFile (pstrSrc As String, pstrTarget As String)
On Error GoTo CopyFile_Err
Dim hfInput As Integer
Dim hfOutput As Integer
Dim lngFilePointer As Long
Dim lngRemain As Long, lngFileLen As Long
Dim strBuffer As String
Dim J As Integer
Dim varDummy As Variant
' Size of buffer to use while copying
Const BYTE_SIZE = 20480
DoCmd Hourglass True
hfInput = FreeFile
' open source file
Open pstrSrc For Binary Access Read Shared As #hfInput
hfOutput = FreeFile
If Len(Dir(pstrTarget)) Then
' Overwrite tartget if exists
Kill pstrTarget
End If
Open pstrTarget For Binary Access Read Write Lock Read Write As
#hfOutput
' Length of file
lngRemain = LOF(hfInput)
lngFileLen = lngRemain
varDummy = SysCmd(SYSCMD_INITMETER, "Copying", lngFileLen)
lngFilePointer = 1
Do Until lngRemain < BYTE_SIZE
strBuffer = Input(BYTE_SIZE, #hfInput)
Put #hfOutput, lngFilePointer, strBuffer
lngRemain = lngRemain - BYTE_SIZE
lngFilePointer = lngFilePointer + BYTE_SIZE
varDummy = SysCmd(SYSCMD_UPDATEMETER, lngFilePointer)
DoEvents
Loop
strBuffer = Input(lngRemain, #hfInput)
Put #hfOutput, lngFilePointer, strBuffer
lngFilePointer = lngFilePointer + lngRemain
varDummy = SysCmd(SYSCMD_UPDATEMETER, lngFilePointer)
DoEvents
Close #hfInput
Close #hfOutput
CopyFile_Exit:
On Error Resume Next
Close #hfInput
Close #hfOutput
DoCmd Hourglass False
varDummy = SysCmd(SYSCMD_REMOVEMETER)
Exit Sub
CopyFile_Err:
Select Case Err
Case Else
End Select
' Retry/Abort/Ignore
Select Case MsgBox(Error, MB_ABORTRETRYIGNORE Or MB_ICONEXCLAMATION,
"Error " & Err)
Case IDABORT
Resume CopyFile_Exit
Case IDRETRY
Resume
Case IDIGNORE
Resume Next
End Select
Exit Sub
End Sub
\|||/
/ \
C o o D
-----------------ooO--u--Ooo-------------------------------
To reply my mail, replace the "nospam" in my address with "trevor",
this was put on in defence of the spam robots that roam usenet.
MS Access FAQ now available on my site below.
http://easyweb.easynet.co.uk/~trevor/
Apathy Error: Don't bother striking any key.