Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    How do you want to 'get' the files in folder? If user browses to folder and then you want code to automatically check each file in the folder, review these examples:



    http://www.freevbcode.com/ShowCode.asp?ID=1487

    http://www.allenbrowne.com/ser-59.html
    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.

  2. #17
    Niriv is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    11
    in this code, is there possibility we could only import data which matches a criteria for given field.

    Public Sub GetScores()
    '-- Import all of the student scores to the tblScores table.
    Dim OurFolder As String
    Dim OurFile As String
    '-- First have the user select the folder
    OurFolder = BrowseFolder1("Select the folder that contains the scores.")
    '-- Dir returns a ZLS ("") when no more files match the criteria
    OurFile = Dir(OurFolder & "\*.txt")
    Do While OurFile <> ""
    '-- I created and saved the ScoreImportSpecs earlier.
    '-- I also created the tblScores table with the following
    '-- four text fields:
    '-- FirstName, LastName, ClassCode, Score
    DoCmd.TransferText acImportDelim, "ICES", "Table1", OurFile
    CurrentDb.Execute "UPDATE table1 SET TYPE='" & Left(OurFile, 1) & "', LISTING='" & Mid(OurFile, 3, 6) & "', FILEDATE=#" & DateSerial(Mid(OurFile, 14, 4), Mid(OurFile, 12, 2), Mid(OurFile, 10, 2)) & "# WHERE LISTING Is Null"
    '-- Get the next *.txt filename
    OurFile = Dir
    Loop
    End Sub
    Import data has field called as "Tariff" data type as number and i want to filter and import only those data whose number start either 25 or 68

  3. #18
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Not with that code. Unless the value to use as criteria is in the file name. In which case it is either import the entire file or nothing. Alternatives are:

    1. open the textfile as an object in VBA and read each line of the file and test for the criteria

    2. set a link to textfile and then query the link just like a table
    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.

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

Similar Threads

  1. Import multiple text files automatically
    By instructorTek in forum Import/Export Data
    Replies: 30
    Last Post: 10-20-2012, 04:50 PM
  2. Replies: 19
    Last Post: 10-08-2012, 07:47 AM
  3. Transfer all text files in a specified folder
    By rtackett in forum Programming
    Replies: 4
    Last Post: 09-10-2012, 11:50 AM
  4. Replies: 1
    Last Post: 06-20-2012, 12:18 PM
  5. Import multiple Text files with a Macro
    By ArchMap in forum Access
    Replies: 3
    Last Post: 07-01-2011, 04:56 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