Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284

    Rename & Move File

    Greetings ~

    Trying to simply take an Excel file from one folder, Rename it and place it in another folder



    The following is throwing a 53 File not Found error

    Code:
    Dim StrFile1 As String
    Dim StrFile2 As String
    Dim FSO As FileSystemObject
    Set FSO = New FileSystemObject
    
    
    StrFile1 = "N:\Sales\Internal\Current\SalesReportCurrent_2019-11-15-04-01-49.xlsx"
    StrFile2 = "N:\Sales\Internal\Archive\SalesReportArchive_20191115.xlsx"
    
    
    Debug.Print StrFile1
    Debug.Print StrFile2
    
    
    FSO.MoveFile "StrFile1", "StrFile2"
    I have also tried: Name "StrFile1" AS "StrFile2"
    Same Error

    Thanks for any help...

    Rt91

  2. #2
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    And just to make sure it's said - Yes both paths and file names exist to the letter

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    use UNC paths in case users dont have the path assigned:
    \\server\Sales\Internal\Current\SalesReportCur...

  4. #4
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    Hey Ranman ~ Thanks for steppin' in...

    No Luck - Same 53 No File Found Error

    I renamed to file in the souce folder to: Boo - just to make sure the spelling was correct

    Same - 53

    I'm assuming the 53 error is pointing to the file in the source folder?

  5. #5
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    As an alternative, try copying the file then deleting the original.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The variables should not have quotes around them. They are being treated as literal strings.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    OMG!!! Really!!!!

    I must crack you up ~ Paul

    Thank You Sir

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    LOL! I'm too busy with my own bone-headed mistakes to laugh at anyone else's.

    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    name vSrc as vTarg

    (it does the move)

  10. #10
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    Can't believe I'm back because of this - This is sooooooooooooo frustrating!!!

    So I un-hard coded the above lines of code - added the necessary variables and boom! Error after error

    Below is what I'm working with
    Code:
    Dim strDate1 As String
    Dim StrFile1 As String
    
    
    Dim strDate2 As String
    Dim StrFile2 As String
    
    
    Dim FSO As FileSystemObject
    Set FSO = New FileSystemObject
    
    
    StrDate1 = Format(Now(), "YYYY-MM-DD"
    StrFile1 = "N:\Sales\Internal\Current\SalesReportCurrent_" & StrDate1 & "*" & ".xlsx"
    StrDate2 = Format(Now(), "YYYYMMDD"
    StrFile2 = "N:\Sales\Internal\Archive\SalesReportArchive_" & StrDate2 & ".xlsx"
    
    
    
    
    Debug.Print StrFile1
    Debug.Print StrFile2
    
    
    
    
    FSO.MoveFile StrFile1, StrFile2
    When I run the above code I receive the following: A 76 Path Not Found Error
    The Debug on StrFile1 = N:\Sales\Internal\Current\SalesReportCurrent_2014-04-14*.xlsx (Seems to be treating the * as a literal string)
    The Debug on StrFile2 is perfect

    Here is an interesting result - When I run the below
    Code:
    Dim strDate1 As String
    Dim StrFile1 As String
    
    
    Dim strDate2 As String
    Dim StrFile2 As String
    
    
    Dim FSO As FileSystemObject
    Set FSO = New FileSystemObject
    
    
    StrDate1 = Format(Now(), "YYYY-MM-DD"
    StrFile1 = Dir("N:\Sales\Internal\Current\SalesReportCurrent_" & StrDate1 & "*" & ".xlsx")
    StrDate2 = Format(Now(), "YYYYMMDD"
    StrFile2 = "N:\Sales\Internal\Archive\SalesReportArchive_" & StrDate2 & ".xlsx"
    
    
    
    
    Debug.Print StrFile1
    Debug.Print StrFile2
    
    
    
    
    FSO.MoveFile StrFile1, StrFile2
    The results returned are a 53 File not found error - and
    the Debug on StrFile1 brings back: SalesReportCurrent_2020-04-14-06-33-43.xlsx - Which is the precise name of the file I'm targeting to move - but the path is ignored

    Help??

    Thank You!!

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I'm confused, do you not know the name of the file? In other words, why the wildcard? The Dir() function returns the file name, not including path. If you need it and the *, then add the path back to the result.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    Hey Paul ~


    I was hoping you'd be out there...

    Ok, the reason for the Wildcard is because part of the file name is randomly generated.

    So the part of the name of each of these uploaded reports (shown in red) is a random sequence of #'s: SalesReportCurrent_2020-04-14-06-33-43.xlsx

    Thus the reason I'm using: SalesReportCurrent_" & StrDate1 & "*" & ".xlsx" with the wildcard

    When you mention to 'add the path back to the result' do you mean something like this:
    Code:
    StrDate1 = Format(Now(), "YYYY-MM-DD"
    StrFile1 = "N:\Sales\Internal\Current\"
    StrFile2 = Dir(StrFile1 & "SalesReportCurrent_" & StrDate1 & "*" & ".xlsx")
    
    StrDate2 = Format(Now(), "YYYMMDD"
    StrFile3 = "N:\Sales\Internal\Archive\SalesReportArchive_" & StrDate2 & ".xlsx"
    
    
    FSO.MoveFile StrFile2, StrFile3
    Last edited by RunTime91; 04-14-2020 at 02:09 PM. Reason: Data Protection

  13. #13
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    This did the trick - But is it correct
    Code:
    StrDate1 = Format(Now(), "YYYY-MM-DD"
    StrFile1 = "N:\Sales\Internal\Current\"
    StrFile2 = Dir(StrFile1 & "SalesReportCurrent_" & StrDate1 & "*" & ".xlsx")
    
    
    StrDate2 = Format(Now(), "YYYMMDD"
    StrFile3 = "N:\Sales\Internal\Archive\SalesReportArchive_" & StrDate2 & ".xlsx"
    
    
    FSO.MoveFile StrFile1 & StrFile2, StrFile3

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Well, you said this produced the correct file name:

    StrFile1 = Dir("N:\Sales\Internal\Current\SalesReportCurrent_ " & StrDate1 & "*" & ".xlsx")

    So I was thinking after that line:

    StrFile1 = "N:\Sales\Internal\Current" & StrFile1

    You could certainly use a variable for the path (I would), but the point was to add the path to the file name.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    Thanks Paul!

    I tried to find something online explaning the result I was getting using the Dir - but found nothing conclusive

    So I didn't understand the results...Now I do

    I went ahead and used a variable for both the path, and the file name of the source and of course the destination path

    Thank You again so very much Paul...

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-30-2015, 05:52 AM
  2. Replies: 6
    Last Post: 08-16-2014, 11:20 AM
  3. rename a PDF File
    By sdel_nevo in forum Programming
    Replies: 3
    Last Post: 08-21-2013, 12:11 PM
  4. Replies: 4
    Last Post: 10-30-2012, 02:54 PM
  5. Have access rename a .txt file and move it
    By dh010010 in forum Programming
    Replies: 5
    Last Post: 07-22-2010, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums