PDA

View Full Version : Browse to File -> Path+File in textbox -> FileCopy to new location



cwdreiling
07-17-2014, 01:57 PM
New to forum and very basic understanding of VBA and Access. However, I have a basic database that I'm creating with tables, queries, forms, etc. I've been racking my brain all day on how to do this but cannot find the answer...

Goal:
Step 1 - The user clicks a button to browse for a file. When the file is selected, the full file name including path appears in a textbox (i.e. C:\Folder1\Folder2\TEST.pdf)
Step 2 - When a different button is clicked, this file is copied to a pre-specified folder and renamed.

From internet searching, I was able to put Step 1 together with minimal issues. So, Step 1 functions properly. My issue is with Step 2, which one would think would be far easier...

Code thus far:

Private Sub but_CopyFile_Click()
Dim SourceFile, DestinationFile As String

SourceFile = Me!txtSelectedFile
DestinationFile = CurrentProject.Path & "\TEST.pdf"

FileCopy SourceFile, DestinationFile


End Sub


With the code as above, Runtime Error 53 File Not Found appears. I know 100% that the file is there, as I can set the textbox to a hyperlink and when clicked it opens the file.

However, if I replace Me!txtSelectedFile with the actual path\file (i.e. "C:\Folder1\Folder2\TEST.pdf" making sure to add the quotations) the code works perfectly and copies the file to the desired location. I have tried adding .Text to Me!txtSelectedFile, .Value to Me!txtSelectedFile, and all sorts of other methods posted online. I'm not sure what the issue is and would greatly appreciate any help.

Thoughts?

jonh
07-17-2014, 11:42 PM
Use the immediate window to print variables to for checking.