Results 1 to 6 of 6
  1. #1
    sailngsue is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    7

    text import


    I have a text file that is one record and uses a ~ as a delimiter between fields.
    I used the DoCmd.transferText Statement
    DoCmd.TransferText acImportFixed = 1, , "NewImport", "W:\NewImport.txt
    It imported as one record creating field names field1....field255.
    What I really want it import it as is one field with as many records as it needs.

    any suggestions?

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I asked for clarification in your first thread but as this is a separate topic, good call in making a new thread.

    Easiest way would be to get an advanced text editor that allows you to replace a character with the return carriage. once you do that, you can import as normal and it will be one word per record.

  3. #3
    sailngsue is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    7
    I have a text editor that can split the fields for me, but I'm trying to automate the process so that a accounting clerk can just push a button.

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    The issue you run into is that in order to do this in Access, you would have to get it into a table in Access first. In your other thread, you mentioned there were 255. That number leads me to believe that there were more words but were truncated due to Access' 255 field limit. Unless you can get your source file to be formatted properly, you are going to run into major issues.

  5. #5
    sailngsue is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    7
    the 255 fields concerned me as well, thats why I re posted here in the import/export area. The solution needs to be as it's being imported. I was hoping I just missed a setting or parameter.

  6. #6
    randman1 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    25
    I do something similar with text files that contain multiple lines of text. Each line is a record in a table containing 14 fields. This is a modification of the code I use so that you can add each of the 255+ records to a table. It's untested and may require some changes to suit your application. You must also add the reference Microsoft Scripting Runtime to your project.

    Code:
    Private Sub ImportFile(sFilePath As String)
        Dim oFso As New FileSystemObject
        Dim oTs As TextStream
        Dim oRs As DAO.Recordset
        Dim vValues() As Variant
        Dim exp As Integer
    
        Set oTs = oFso.OpenTextFile(sFilePath, ForReading)
        vValues = Split(oTs.ReadAll, "~")
    
        Set oRs = CurrentDB.OpenRecordset("YourTableName", , dbAppendOnly)
        For exp = 0 To UBound(vValues)
            oRs.AddNew
            oRs!YourFieldName = vValues(exp)
            oRs.Update
        Next exp
    
        oRs.Close
    
    End Sub
    Last edited by randman1; 09-28-2011 at 04:03 AM.

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

Similar Threads

  1. Import Text from a Website
    By P5C768 in forum Import/Export Data
    Replies: 3
    Last Post: 10-06-2010, 07:35 AM
  2. Text Import Specs
    By orcinus in forum Access
    Replies: 3
    Last Post: 06-23-2010, 11:50 AM
  3. Text import
    By gsashwin in forum Access
    Replies: 3
    Last Post: 06-22-2010, 05:01 PM
  4. Import to text - only text value NOT importing
    By Gerry in forum Import/Export Data
    Replies: 10
    Last Post: 03-26-2010, 06:55 AM
  5. import text specification
    By brunoylupe in forum Import/Export Data
    Replies: 12
    Last Post: 08-09-2009, 04:47 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