Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How copy a file

1 view
Skip to first unread message

Alberto Rausa

unread,
Feb 17, 1998, 3:00:00 AM2/17/98
to

Can i copy a file from VBA and Access2?

Thank!

Alberto Rausa

Dev Ashish

unread,
Feb 19, 1998, 3:00:00 AM2/19/98
to

Hi,

Try the article Q102671 in Microsoft's Support site.

btw it's called Access Basic in version 2.0, not VBA.

HTH
--
Just my $.001
Dev Ashish
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

Alberto Rausa wrote in message <34e9b922...@news.tin.it>...
:Can i copy a file from VBA and Access2?
:
:Thank!
:
: Alberto Rausa

D Paul Phillips

unread,
Feb 19, 1998, 3:00:00 AM2/19/98
to

Alberto Rausa wrote:
>
> Can i copy a file from VBA and Access2?
>
> Thank!
>
> Alberto Rausa
Yes you can! Example Below:

Dim SourceFile As String
Dim DestinationPath As String
Dim MyFile As String
Dim Message As String

CommonDialog1.Flags = &H1000 Or &H4
CommonDialog1.DialogTitle = "Copy Template"
CommonDialog1.InitDir = [Forms]![Admin Menu]![PTH]
CommonDialog1.FileName = "*.doc"
CommonDialog1.Filter = "Word 7.0 Document (*.doc)|*.doc"
CommonDialog1.ShowSave
CommonDialog1.DefaultExt = "doc"
SourceFile = CommonDialog1.FileName
DestinationPath = CommonDialog1.FileTitle
MyFile = Dir([Forms]![Admin Menu]![PTH] & DestinationPath)
If MyFile = CommonDialog1.FileTitle Then
Message = CommonDialog1.FileTitle & " already
exists in this directory. Overwrite?"
If MsgBox(Message, vbYesNo, "Error!") = vbYes Then
On Error Resume Next
[Forms]![Categories]![TestFileName] =
CommonDialog1.FileTitle
FileCopy SourceFile, [Forms]![Admin Menu]![PTH] &
DestinationPath
DoCmd.Close acForm, "Categories", acSaveYes
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, ,
acMenuVer70
End If
Else
On Error Resume Next
If CommonDialog1.FileTitle <> "" Then
[Forms]![Categories]![TestFileName] =
CommonDialog1.FileTitle
FileCopy SourceFile, [Forms]![Admin Menu]![PTH]
& DestinationPath
DoCmd.Close acForm, "Categories", acSaveYes
Else
End If
End If

Jürg Wild

unread,
Feb 20, 1998, 3:00:00 AM2/20/98
to

just use the access statement

filecopy source, dest

Michael Kaplan

unread,
Feb 22, 1998, 3:00:00 AM2/22/98
to

This is a great A96/A97 solution.... but it will not work in Access 2....

Michael

D Paul Phillips <dpph...@mail.delcoelect.com> wrote in message
news:34EC8D...@mail.delcoelect.com...

Trevor Best

unread,
Feb 26, 1998, 3:00:00 AM2/26/98
to

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.

0 new messages