Results 1 to 8 of 8
  1. #1
    enzokevin is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    13

    Renaming Files using data from a table or query

    I need help with a code to rename photos (Access 2010). The new name (full path) is listed on a table (although I would love to accomplish the task from the list query that I later used to generate the table). There is one field in the table (or query) called OldPath and one field called NewPath. The table name is RenPaths. Both paths are located in the same drive. I want to rename the file in a new folder. I created the new folder which is contained in the NewPath.
    I was trying to accomplish this using the Name function
    Name OldPath as NewPath

    Here is the full code:

    Code:
    Private Sub Command0_Click()
    Dim rs As DAO.Recordset
    Dim db As DAO.Database
    Dim OldPath As String
    Dim NewPath As String
    OldPath = "Select OldPath From RenPaths"
    NewPath = "Select NewPath From RenPaths"
    Set db = CurrentDb
    Set rs = db.OpenRecordset(OldPath)
    With rs
    Do While Not rs.EOF
    Name OldPath As NewPath
    .MoveNext
    Loop
    End With
    rs.Close
    Set rs = Nothing
    End Sub
    Im getting an error: Run time error '53': File not found
    I checked the OldPath and everything is correct so if the code is working correctly it should have found the file. Help identifying the problem is appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    Be sure you use the ENTIRE path on BOTH , \\folder1\folder\file.xl
    if network, dont use drive letter paths, us the full UNC path : \\server1\folder1\folder2\file.xls

    (yes drive letters work, but not for all)

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    This may help with renaming files/folders.

  4. #4
    enzokevin is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    13
    Yes, I am using the entire path. For example
    Old Path is - C:\Users\kcrespo\Documents\Fulcrum to MACP\Fulcrum_Export_a97dee97-ba92-455e-9d5c-3b35617ad357\SAA Inspection Form\367e14e0-439b-4a50-99e1-9154bcc9e3f7.jpg
    New Path is - C:\Users\kcrespo\Documents\Fulcrum to MACP\Fulcrum_Export_a97dee97-ba92-455e-9d5c-3b35617ad357\SAA Inspection Form\images\wwMH51856_A3f7.jpg
    so I don't think that is the problem

  5. #5
    enzokevin is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    13
    Orange:
    I did some research on the matter before I posted the question and I did reached the link you gave me. But what I could not understand in the code is how is the value (old path and new path, in this case strSource and strTarged) assigned to the variables. In other word I don't know how to adjust the code to my need (how to pull the values from my table into the code).
    I forgot to mention I'm not a programmer.

  6. #6
    enzokevin is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    13
    I finally figure out to accomplish what I needed. Here is how the final code looks like in case someone needs it.

    Code:
    Private Sub Command0_Click()
    Dim rsFolders As DAO.Recordset
      
      Set rsFolders = CurrentDb.OpenRecordset("SELECT DISTINCT [OldPath], [NewPath] FROM RenPaths")
      Do While Not rsFolders.EOF
                           ' Check that Old Path exists.
        If Len(Dir(rsFolders![OldPath], vbDirectory)) > 0 Then
                            ' Check that New Path doesn't exist.
          If Len(Dir(rsFolders![NewPath], vbDirectory)) = 0 Then
            Name rsFolders![OldPath] As rsFolders![NewPath]
          End If
        End If
        rsFolders.MoveNext
      Loop
      rsFolders.Close
      Set rsFolders = Nothing
    End Sub

  7. #7
    joelgood is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    1
    well, i am a regular coder, but this code is new to me.. i will try it...
    online casinos
    Last edited by joelgood; 10-18-2014 at 12:46 AM.

  8. #8
    enzokevin is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    13
    One thing about this code. I will actually MOVE and rename the file. If you want to also keep the original files. Make a backup copy before running the code.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-29-2013, 02:39 AM
  2. Replies: 7
    Last Post: 08-27-2012, 10:28 AM
  3. Replies: 5
    Last Post: 01-30-2012, 01:14 PM
  4. Renaming Fields on Table or Query
    By jo15765 in forum Access
    Replies: 4
    Last Post: 12-09-2010, 01:47 PM
  5. Edit a table in a query by renaming the query?
    By TheWolfster in forum Queries
    Replies: 2
    Last Post: 07-30-2010, 02:57 PM

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