Copy File Code Help????? (1 Viewer)

stpiepgr

Member
Local time
Today, 15:46
Joined
Nov 6, 2002
Messages
25
I originally posted this under the Forms discussion but feel that this may be more appropriate

I have a database on map plots that users access from a network drive. Users have an option of adding a new plot record and I would like to have button that allows the user to select and then copy the file from their local drive to the network location for others to access. I would also like to be able to do the opposite..click a button and copy the desired network file to their local drive for printing. Is this possible and how would it be done.

I received the following code from Shadez

Private Sub Command58_Click()
Dim fs As Variant

Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile Source, destination, [overwrite]

End Sub

When I place this in the OnClick event but when I run the code I get another Run Time Error 2465 saying that it can't find the field "form" specified in the expresssion.

I don't know enough about this to figure what I am doing wrong. Any help would be greatly appreciated!
 

chewy

SuperNintendo Chalmers
Local time
Today, 15:46
Joined
Mar 8, 2002
Messages
581
This is what I have for a file copy. Use your file names for strFile1 and strFile2

Function fCopyFile(strFile1 As String, strFile2 As String)

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile strFile1, strFile2, True

End Function
 

stpiepgr

Member
Local time
Today, 15:46
Joined
Nov 6, 2002
Messages
25
I know it has been a while since I put this forward this but I got pulled away on some more "important" projects. I am still having problems getting this to work. Chewy....when I place this on the OnClick event I get an error that the VB is looking for an expectant EndSub. Additionally will this function allow the user to pick the files to copy (i.e. Windows explorer type of interface) or will it only copy the file currently displayed on the form. My current lack of ability in this area is frustrating me!!!!!
 

chewy

SuperNintendo Chalmers
Local time
Today, 15:46
Joined
Mar 8, 2002
Messages
581
Post what code you are using. It is going to copy one file. That function will not allow you to choose a file but it wouldn't be hard to do. Let me know
 

stpiepgr

Member
Local time
Today, 15:46
Joined
Nov 6, 2002
Messages
25
Here is what I have placed in the OnClick Event:

Private Sub Command58_Click()
Function fCopyFile(Image1.eps As String, Image2.eps As String)

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile Image1.eps, Image2.eps, True
End Function
End Sub

Thanks,

Steve
 

Shadez

Registered User.
Local time
Today, 15:46
Joined
Jan 20, 2003
Messages
192
Soz U should of said u were a vb nOOb

ill make it simple for you

Sub CopyFile(FileNameAndPath As String, FileNameAndDestination As String)
Dim FSO As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile FileNameAndPath, FileNameAndDestination, True

End Sub



copy this into ur code make sure u dont place it in the middle of an existing funtion.


Next replace ur existing _click with this one. Edit the filenames and paths as required.

Private Sub Command58_Click()
CopyFile "C:\Somewhere\aFile.txt", "\\NetworkServer\ADir\aFile.txt"

End Sub


:cool:ShadeZ:cool:
 

chewy

SuperNintendo Chalmers
Local time
Today, 15:46
Joined
Mar 8, 2002
Messages
581
A little crude but just did it in a hurry. But should do what you need
 

Attachments

  • file copy .zip
    37.4 KB · Views: 131

stpiepgr

Member
Local time
Today, 15:46
Joined
Nov 6, 2002
Messages
25
Ahhhhh....now I see the error of my ways. That appears to have fixed the problem and everything seems to be working. Chewie and Shadez....thanks for providing this "novice" with a little help. Learn something new everyday!
 

Users who are viewing this thread

Top Bottom