Results 1 to 8 of 8
  1. #1
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185

    Capture File Name

    Hi,

    I am looking for some help to capture file names in 1 directory and insert them in a table so that I can find duplicates.



    any help would be appreciated

    Thanks,
    Nick

  2. #2
    SodaPop is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2014
    Posts
    16
    Quote Originally Posted by nick243 View Post
    Hi,

    I am looking for some help to capture file names in 1 directory and insert them in a table so that I can find duplicates.

    any help would be appreciated

    Thanks,
    Nick
    Make it a collection and cycle through. Set each file as a variable for an sql query.

    Dim strcolsubfolder as new collection
    Dim strfolder as string
    Dim strsql as string
    Subfolder = "filelocatiinyouwanttoinspect"

    Strsubfoler = dir(strfolder & "*", vbdirectory)
    Do while not strsubfolder = ""
    Select case ".", ".."
    Colsubfolder.add item:=strsubfolder, key:=strsubfolder
    And select
    Strsubfolder = dir

    Strsql = " Sql to append record based on strsubfolder"

    Docmd.runsql strsql
    Loop



    Sent from my SM-G950U using Tapatalk

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    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.

  4. #4
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    Thank you for the responses

    I put in the directory location but I am not sure how to create the sql statement. What information do I need to create the sql correctly.

    Thanks,
    Nick

    Make it a collection and cycle through. Set each file as a variable for an sql query.

    Dim strcolsubfolder as new collection
    Dim strfolder as string
    Dim strsql as string
    Subfolder = "filelocatiinyouwanttoinspect"

    Strsubfoler = dir(strfolder & "*", vbdirectory)
    Do while not strsubfolder = ""
    Select case ".", ".."
    Colsubfolder.add item:=strsubfolder, key:=strsubfolder
    And select
    Strsubfolder = dir

    Strsql = " Sql to append record based on strsubfolder"

    Docmd.runsql strsql
    Loop

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I am not sure about SodaPop's code but following the Allen Browne example, like:

    CurrentDb.Execute "INSERT INTO tablename(fieldname) VALUES('" & StrFileName & "')"

    SodaPop is building a Collection and Allen is building an array. If you want to write record to table, neither collection nor array are needed.
    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.

  6. #6
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    Quote Originally Posted by June7 View Post
    I am not sure about SodaPop's code but following the Allen Browne example, like:

    CurrentDb.Execute "INSERT INTO tablename(fieldname) VALUES('" & StrFileName & "')"

    SodaPop is building a Collection and Allen is building an array. If you want to write record to table, neither collection nor array are needed.
    Yes I would just like to write to a table.

    Thanks for your help.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Here is another Allen Brown link that shows how to loop through folder http://allenbrowne.com/ser-59.html (Allen uses Collection).

    Instead of building a collection and setting a combo or list box list, write records to table. Simple version of code:

    Code:
    Public Sub GetFiles()
        Dim strFile As String
        strFile = Dir("C:\yourfolderpath\*.*")
        Do While strFile <> ""
            If (strFile <> ".") And (strFile <> "..") Then
                CurrentDb.Execute "INSERT INTO Files(FileName) VALUES('" & strFile & "')"
            End If
            strFile = Dir
        Loop
    End Sub
    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.

  8. #8
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    Quote Originally Posted by June7 View Post
    Here is another Allen Brown link that shows how to loop through folder http://allenbrowne.com/ser-59.html (Allen uses Collection).

    Instead of building a collection and setting a combo or list box list, write records to table. Simple version of code:

    Code:
    Public Sub GetFiles()
        Dim strFile As String
        strFile = Dir("C:\yourfolderpath\*.*")
        Do While strFile <> ""
            If (strFile <> ".") And (strFile <> "..") Then
                CurrentDb.Execute "INSERT INTO Files(FileName) VALUES('" & strFile & "')"
            End If
            strFile = Dir
        Loop
    End Sub
    This work great thank you

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

Similar Threads

  1. Capture Value From listbox
    By jo15765 in forum Programming
    Replies: 1
    Last Post: 05-29-2017, 06:11 PM
  2. Capture MAX() Value From Table In VBA
    By jo15765 in forum Programming
    Replies: 2
    Last Post: 05-23-2017, 09:25 AM
  3. Data Capture app
    By Homegrownandy in forum Access
    Replies: 8
    Last Post: 09-24-2015, 09:02 AM
  4. Replies: 5
    Last Post: 01-15-2011, 01:35 AM
  5. Capture 2nd Value in an unbound Combo.
    By sesproul in forum Forms
    Replies: 5
    Last Post: 04-30-2010, 02:07 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