Page 2 of 2 FirstFirst 12
Results 16 to 16 of 16
  1. #16
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    If I'm reading this right, You have a table with names. Those names correspond to photo names, in a particular folder, and the extensions may not all be the same.


    You want to import the paths to those photos and match them to the names in the table. You have a large number of photos so you want to do it in bulk.

    You can use the GetBasename method of FileScriptingObject to do this.

    Code:
    Sub UpdateFiles2Table(strFolder As String)
    
    
        Dim strSql As String
        Dim fil As File
        Dim fldr As Folder
        Dim db As DAO.Database
    
    
        If strFolder = "" Then Exit Sub
    
    
        Set db = CurrentDb
    
    
        Dim fso As New FileSystemObject
    
    
        Set fldr = fso.GetFolder(strFolder)
    
    
        For Each fil In fldr.Files
    
    
            strSql = "Update Table2 set h = """ & fil.Path & """ where b = """ & fso.GetBaseName(fil.Path) & """"
    
    
            Debug.Print strSql
            db.Execute strSql, dbFailOnError
    
    
        Next
    
    
        Set fso = Nothing
        Set db = Nothing
    
    
    End Sub
    You would call it with something like this:

    Code:
    Sub GetEm()
         UpdateFiles2Table ("C:\Users\DANESH\Downloads\Telegram Desktop\photos")
    End Sub
    GetBaseName returns the filename without the extension so it will match the name with the filename.
    This procedure loops through the folder and updates your table with the filepath where the Name matches the basename.

    EDIT: You need to set a reference to Microsoft Scripting Runtime
    Last edited by moke123; 08-19-2021 at 04:53 AM.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. file format or extension not valid.
    By Homegrownandy in forum Programming
    Replies: 6
    Last Post: 02-05-2018, 07:24 AM
  2. Use FileDialog to get file with txt extension
    By newbieX in forum Programming
    Replies: 4
    Last Post: 01-11-2016, 07:28 PM
  3. Need to import .txt file using the extension only.
    By PJ Crittenden in forum Macros
    Replies: 3
    Last Post: 06-24-2014, 07:10 PM
  4. Replies: 1
    Last Post: 03-18-2014, 05:16 PM
  5. access file extension help
    By supertech33 in forum Access
    Replies: 2
    Last Post: 02-17-2010, 03:31 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