Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Importing a series of txt documents

Discussion in 'Information Technology' started by rls0905, Jul 28, 2006.

  1. rls0905

    rls0905
    Expand Collapse
    Guest

    I need to write code that will import all txt documents in a specified file
    location. Maybe a For Each...Next?
     
  2. Loading...

    Similar Threads Forum Date
    Sikh Foundation Sikhi is not What but How: A 4-Part Series Sikh Organisations Oct 20, 2013
    1984 RTI Judgement Series: Missing Reports of 1984 Sikh Riots History of Sikhism Mar 20, 2013
    Christianity The Bible TV Series Interfaith Dialogues Mar 10, 2013
    Sheikh Farid ji Bani/ਸੇਖ ਫਰੀਦ ਜੀਉ ਕੀ ਬਾਣੀ – No. 4 in Series Bani Sheikh Farid Apr 8, 2012
    Sheikh Farid ji Bani/ਸੇਖ ਫਰੀਦ ਜੀਉ ਕੀ ਬਾਣੀ – No. 3 in Series Bani Sheikh Farid Apr 6, 2012

  3. Teh Brian

    Teh Brian
    Expand Collapse
    Guest

    You could make a batch file with a command like "dir/b>filedump.txt" to
    create a text file with all the file names in a given directory. Then
    run the batch file from access with the DoCmd.RunApp method. You could
    then import the "filedumpt.txt" file using the TransferText method to
    create a table of file names. Then import all the file names from the
    imported table by using a loop. This could be accomplished using a
    recordset of the table called "rec" for instance (rec.MoveFirst and
    rec.MoveNext seem like they would be handy here)
    Good Luck
     
  4. Pieter Wijnen

    Pieter Wijnen
    Expand Collapse
    Guest

    Or

    Dim FName As String

    FName = Dir("C:\temp\*.txt)
    While Len(FName)
    DoCmd.Transfertext ...
    Fname=Dir()
    Wend


    HTH

    Pieter

    "Teh Brian" <bcMcKinley@gmail.com> wrote in message
    news:1148325542.260990.17800@u72g2000cwu.googlegroups.com...
    > You could make a batch file with a command like "dir/b>filedump.txt" to
    > create a text file with all the file names in a given directory. Then
    > run the batch file from access with the DoCmd.RunApp method. You could
    > then import the "filedumpt.txt" file using the TransferText method to
    > create a table of file names. Then import all the file names from the
    > imported table by using a loop. This could be accomplished using a
    > recordset of the table called "rec" for instance (rec.MoveFirst and
    > rec.MoveNext seem like they would be handy here)
    > Good Luck
    >
     
  5. Teh Brian

    Teh Brian
    Expand Collapse
    Guest

    Pieter is right; this is a much more elegant solution. Remember the
    second quote in the 'FName =' line

    FName = Dir("C:\temp\*.txt")
     
  6. Pieter Wijnen

    Pieter Wijnen
    Expand Collapse
    Guest

    caught me out cold again <g>

    Pieter

    "Teh Brian" <bcMcKinley@gmail.com> wrote in message
    news:1148394929.832611.212850@j33g2000cwa.googlegroups.com...
    > Pieter is right; this is a much more elegant solution. Remember the
    > second quote in the 'FName =' line
    >
    > FName = Dir("C:\temp\*.txt")
    >
     
  7. gdaniels

    gdaniels
    Expand Collapse
    Guest

    Hi, I need some help. The routine below runs when a command button is
    clicked. A prompt appears to enter the directory path to the folder
    containing delimited text files to be imported into an Access 97 table.
    The test folder contains 9 files. The problem is that the 1st file is
    imported 9 times into the table. How do I correct the routine so it
    loops properly and imports each file? Thanks in advance.



    Gary


    Private Sub Command0_Click()
    Dim InputDir, ImportFile As String, tblName As String
    Dim InputMsg, Name As String

    InputMsg = "Type the pathname of the folder that contains "
    InputMsg = InputMsg & "the files you want to import."
    InputDir = InputBox(InputMsg)
    ' Change the file extension on the next line for the
    ' type of file you want to import.
    ImportFile = Dir(InputDir & "\*.txt")
    Name = ((InputDir) & ("\") & (ImportFile))
    Do While Len(ImportFile) > 0
    ' Use the import file name without its extension as the table
    ' name.
    tblName = "Expenses"

    DoCmd.TransferText [acImportDelim], "Batch", "ExpBatch", Name
    ImportFile = Dir
    Loop
    End Sub



    --
    gdaniels
    ------------------------------------------------------------------------
    Posted via http://www.mcse.ms
    ------------------------------------------------------------------------
    View this thread: http://www.mcse.ms/message2333060.html
     

Share This Page