Solved Moving a file with click of a button

donkey9972

Registered User.
Local time
Yesterday, 18:12
Joined
May 18, 2008
Messages
192
Ok, I have half of my problem solved, I just have no idea how to incorporate the 2nd half. So using a simpletext box, and button I can use the filedialog to select a file which I have done, How do I take that file location that is now appearing in the text box and move that file to a specific destination location? Note that the destination location will always be the same, so that can be put into the code or VBA without an issue. What is always changing is the location the file is coming from.
 

Attachments

I saw the filecopy but it requires a source file to be defined in the code. I am trying to find an option that takes the source file from whatever the user selects in the FileDialog method that appears in the textbox on the form.
 
You can use the VBA Name statement

eg.
Code:
Dim FileName As String
Const DESTINATION_PATH As Strin = "C:\Path\To\Move\File\"

If Len(Me.txtSelectedFilePath & vbNullString) > 0 Then
  ' Get file name
  FileName = Mid(Me.txtSelectedFilePath, InStrRev(Me.txtSelectedFilePath, "\") + 1)
  ' Do the move
  Name Me.txtSelectedFilePath As DESTINATION_PATH & FileName
End If
 
You can use the VBA Name statement

eg.
Code:
Dim FileName As String
Const DESTINATION_PATH As Strin = "C:\Path\To\Move\File\"

If Len(Me.txtSelectedFilePath & vbNullString) > 0 Then
  ' Get file name
  FileName = Mid(Me.txtSelectedFilePath, InStrRev(Me.txtSelectedFilePath, "\") + 1)
  ' Do the move
  Name Me.txtSelectedFilePath As DESTINATION_PATH & FileName
End If
Doesn't this still require the old file name to be put into the code? At least what I was reading in the link you provided that is what it seems to me.
 
I found my mistake on it. You are right, this does exactly as was needed. Thank you.
 

Users who are viewing this thread

Back
Top Bottom