Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Word document from C: drive to server drive 1

Status
Not open for further replies.

nastar1

Technical User
Nov 1, 2005
122
US
Users would like me to add a button to a form that would allow them to browse a word doc or other file on thier C: drive and then save it to a network server folder.

I presently have a button with a Click event with the following:

Me.TaskDescrip.SetFocus
RunCommand acCmdInsertHyperlink

So I need to add code if possible to this Click event that would save the document to a server folder before the RunCommand. The source documents will most likely be created in the C:\My Docs folder, but there may be exceptions. But the goal of the Save action in this Click event will save the browsed document to the same server folder. So I should be able to hard code that location into the code if necessary.

Any ideas?
 
Thanks jrbarnett,

That first FileCopy should do the trick.

I could use a kick start on how to substitute the source filename with the value from the txtTaskDescrip field as well as how to substitute the target filename with the txtTaskDesrip field appended to my new target path.

I've seen this type of coding before but am not experienced enough to recall how to do it. I'm assuming I've got to capture/store the txtTaskDescrip as a variable and then append it to the path in both cases.

Thanks
 
To adapt the original one there:

Code:
Sub Copy_One_File(strInputFile As String, strDest As String)
    FileCopy strInputFile, strDest
End Sub

So you then just call it

Copy_One_File "C:\My Documents\" & Me!txtTaskDescrip, "S:\Server\" & Me!txtTaskDescrip

This assumes that the txtTaskDescrip field contains just a filename - for example file1.abc or file2.xyz.

For the few exceptions where a full path is supplied a minor modification - for example to check if the source file exists before attempting the copy. eg:

Copy_One_File v2

Code:
Function Copy_One_Filev2(strInputFile As String, strDest As String) As Boolean
    If Dir (strInputFile) = "" Then 
        FileCopy strInputFile, strDest
        If Dir (strDest) = "" Then
            ' Copy succeeded
            Copy_One_Filev2 = True
        Else
            Copy_One_Filev2 = False
        End If
    Else
        Copy_One_Filev2 = False
    End If
End Function

You can now check to see if the file copy worked - eg

Code:
If Copy_One_Filev2 ("C:\My Documents\" & Me!txtTaskDescrip, "S:\Server\" & Me!txtTaskDescrip) = True Then 
   Msgbox "File copy worked"
Else
   Msgbox "File copy failed"
End If

Reasons for a failure could be along the lines of insufficient permissions on the destination folder, an existing file on there with the same name being read only etc.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top