Results 1 to 7 of 7
  1. #1
    Karl1135 is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2024
    Posts
    3

    File not found (error 53) when using Name command.

    I am trying to remove the extra periods in a downloaded file so TransferText will work to import the file. TransferText doesn' t like the extra periods. The following code returns file not found (error 53). The files exists. Can copy the file name in Windows explorer and file opens. Also Dir works.

    Dim OldName As String, NewName As String


    OldName = Me.AmzFileName
    NewName = Me.NewAmzFileName


    Debug.Print OldName
    Debug.Print NewName
    Debug.Print Dir(OldName)

    Debug.print shows


    C:\Users\Karl\Downloads\AMZOrders02-24\Retail.CustomerReturns.1\Retail.CustomerReturns .1.csv
    C:\Users\Karl\Downloads\AMZOrders02-24\RetailCustomerReturns1\RetailCustomerReturns1.c sv
    Retail.CustomerReturns.1.csv

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    NewName removes periods from folder name as well as file name. Did you actually rename folder as well as file? I don't see any code that renames anything.

    Please post code between CODE tags to retain formatting and readability.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Karl1135 is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2024
    Posts
    3
    Quote Originally Posted by Karl1135 View Post
    I am trying to remove the extra periods in a downloaded file so TransferText will work to import the file. TransferText doesn' t like the extra periods. The following code returns file not found (error 53). The files exists. Can copy the file name in Windows explorer and file opens. Also Dir works.

    Dim OldName As String, NewName As String


    OldName = Me.AmzFileName
    NewName = Me.NewAmzFileName


    Debug.Print OldName
    Debug.Print NewName
    Debug.Print Dir(OldName)

    Debug.print shows
    C:\Users\Karl\Downloads\AMZOrders02-24\Retail.CustomerReturns.1\Retail.CustomerReturns .1.csv
    C:\Users\Karl\Downloads\AMZOrders02-24\RetailCustomerReturns1\RetailCustomerReturns1.c sv
    Retail.CustomerReturns.1.csv
    Edit Added:
    Name OldName As NewName

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    As I already pointed out, your code removes periods from folder name in the string but does not actually rename the folder so of course the Name command cannot find that path for renaming file.

    Why create folder that has same name as file?

    Quoting your own post is not placing code between CODE tags. Unnecessary to quote your post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Have you tried FSO?

    Something like this will rename the file in the same folder.
    You can modify it with various options.

    Code:
    Private Sub sRenameCsv(FPath As String, NewName As String)
    
        Dim fil As Object, FExt As String, PFol As String
        
        'late binding
            Dim fso As Object
            Set fso = CreateObject("Scripting.FileSystemObject")
        
        'early binding
        'Dim fso As New FileSystemObject
    
        Set fil = fso.GetFile(FPath)
    
        FExt = "." & fso.GetExtensionName(FPath)  'get the file extension
    
        PFol = fso.GetParentFolderName(FPath)     'get the parent folder path
        
        If Not fso.FileExists(fso.BuildPath(PFol, NewName & FExt)) Then  'check that the re-named file does not exist
        
            fso.MoveFile FPath, fso.BuildPath(PFol, NewName & FExt)  'move the file to same folder with new name
        Else
            MsgBox "File already exists"
        End If
    
        Set fso = Nothing
    
    End Sub
    If the periods(.) in the directory names are a problem, you can rename and move the file to a different folder


    Code:
    Private Sub sRenameMoveCsv(FPath As String, NewFolderPath As String, NewName As String)
    'FPath - Path to the file to rename
    'NewFolderPath - path to the folder to save file to.
    'NewName - new file name
    
    
        Dim fil As Object, FExt As String, PFol As String
        
        'late binding
            Dim fso As Object
            Set fso = CreateObject("Scripting.FileSystemObject")
        
        'early binding
        'Dim fso As New FileSystemObject
    
    
        Set fil = fso.GetFile(FPath)
    
    
        FExt = "." & fso.GetExtensionName(FPath)  'get the file extension
       
        If Not fso.FileExists(fso.BuildPath(NewFolderPath, NewName & FExt)) Then  'check that the re-named file does not exist
        
            fso.MoveFile FPath, fso.BuildPath(NewFolderPath, NewName & FExt)  'move the file to new folder with new name
        Else
            MsgBox "File already exists"
        End If
    
    
        Set fso = Nothing
    
    
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    Karl1135 is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2024
    Posts
    3
    Quote Originally Posted by June7 View Post
    As I already pointed out, your code removes periods from folder name in the string but does not actually rename the folder so of course the Name command cannot find that path for renaming file.

    Why create folder that has same name as file?

    Quoting your own post is not placing code between CODE tags. Unnecessary to quote your post.

    Only option I see is "Reply with quote". Don't see Reply only. New users may not see that.
    New Destination folder exists
    Solved using another posters suggestion to use FSO.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    So what does this picture show?
    Attached Thumbnails Attached Thumbnails Screenshot_20240306-211621_Chrome.jpg  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. File Not Found Error in Module
    By rcrobman in forum Modules
    Replies: 23
    Last Post: 03-07-2019, 07:21 PM
  2. Error : File not found
    By CoZak in forum Programming
    Replies: 5
    Last Post: 06-29-2018, 02:32 AM
  3. File Not Found error
    By polbit in forum Access
    Replies: 7
    Last Post: 07-10-2014, 09:54 AM
  4. Error importing Excel file re search key not found
    By pcbrush in forum Import/Export Data
    Replies: 1
    Last Post: 10-03-2013, 03:19 PM
  5. Intercepting error codes like 2220, file not found
    By justphilip2003 in forum Programming
    Replies: 4
    Last Post: 04-21-2013, 11:33 AM

Tags for this Thread

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