Copy a file on button click?

sjd

Registered User.
Local time
Today, 17:56
Joined
Jun 19, 2012
Messages
34
Is it possible in access, to create a button that will copy a file to a new directory?

Specifically, the data field in question is an access hyperlink that we can click on to open a PDF drawing of a part. I just want to copy the file the hyperlink points to, into a new directory.

EX:
X:database/drawings/somefile.pdf
X:erp/drawings/somefile.pdf

I don't think a macro can do this, but perhaps vbscript can.
 
Is it possible in access, to create a button that will copy a file to a new directory?

Specifically, the data field in question is an access hyperlink that we can click on to open a PDF drawing of a part. I just want to copy the file the hyperlink points to, into a new directory.

EX:
X:database/drawings/somefile.pdf
X:erp/drawings/somefile.pdf

I don't think a macro can do this, but perhaps vbscript can.

I'm sure a Macro could do it but I'm not into Macros.

For VBA the command you want is : FileCopy.

You use it like so,

FileCopy strSource, strDestination

Using your example

FileCopy "X:database/drawings/somefile.pdf", "X:erp/drawings/somefile.pdf"
 
Last edited:
Thank you for the information. In my specific case, I am going to parse the hyperlink from a control on the form itself. See code below.

Code:
Private Sub button_name_Click()
    Dim oldFileName, newFileName, newLoc As String
    Dim msgNoHyperLink, msgNoFile, msgCopy As String
    Dim LResponse As Integer
    
    newLoc = "X:\Folder\Drawings\"
    oldFileName = HyperlinkPart(Forms![<Form Name>]![<Control Name>], acFullAddress)
    oldFileName = Replace(oldFileName, "%20", " ") ' convert %20 back to spaces, comment out if unwanted behavior
    newFileName = newLoc + Dir(oldFileName)
    
    ' messages
    msgNoHyperLink = "Hyperlink Not Entered Error:" + vbNewLine + vbNewLine + "Please attach part drawing print before attempting to copy."
    msgNoFile = "Error: File Not Found" + vbNewLine + vbNewLine + "Please verify " + oldFileName + " file exists."
    msgCopy = "Copying File: " + vbNewLine + oldFileName + vbNewLine + vbNewLine + "To: " + vbNewLine + newFileName
    
    If IsEmpty(Forms![<Form Name>]![<Control name>]) Or Len(Nz(Forms![<Form Name>]![<Control name>])) = 0 Then
        LResponse = MsgBox(msgNoHyperLink, vbCritical)
        
    ElseIf IsEmpty(oldFileName) Or Len(Dir(oldFileName)) = 0 Then
        LResponse = MsgBox(msgNoFile, vbCritical)
        
    Else
        LResponse = MsgBox(msgCopy, 4, "Copy File?")
        If LResponse = 6 Then
            FileCopy oldFileName, newFileName
        End If
        
    End If
    
End Sub
This code seems to work perfectly. Posting in case anyone needs something similar one day.

It could probably make use of FileSystemObject instead, might be less lines that way. But this works fairly well.
 

Users who are viewing this thread

Back
Top Bottom