Results 1 to 6 of 6
  1. #1
    robert315 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    3

    Post Import text file, multiple lines and varying delimiters/size to one record

    Using MS 2007, I have a 200 text files exported each day from another application that has two different types of lines (see below). I would like to import each text file in to a database as a single record.



    Text file example (text.txt):
    R111 WC 8/21/2012 7:00 Doe, John doej 10110110
    First Question? Y
    Second Question? N
    Third Question? Y
    ...
    Seventeenth Question? 10

    As you see, I have the first row with multiple fields, but the next rows I have a question and an answer.

    I would like to have this data imported as shown in the attachment.
    Example.zip

    Most answers I see are for either multiple lines (same data and sizing). I am not sure how to handle several different lines with that vary in size and delimiters. Any help would be appreciated.
    Last edited by robert315; 08-22-2012 at 12:11 PM. Reason: Text Spacing messed up how the information looks.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If there is a consistent pattern, can be programmed.

    Each file will be a single record?

    All files have the same number of lines?

    First line is always header information and has same structure?

    All other lines have question mark?

    Just a matter of reading each line and applying conditional statements to determine how to deal with it. Rough example:

    'code to open text file
    'code to open editable recordset of table and add new record
    For i = 1 to 18
    strLine = code to read line from text file
    If InStr(strLine, "?")>0 Then
    'code to set value of answer field in recordset - is question needed to be saved?
    Else
    'code to populate recordset fields with header information
    End If
    'code to move to next line of text file
    Next

    This is an exercise in logic and using the proper code structure to apply the logic. Write and test code. When you hit issue you can't resolve, post code for analysis.
    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.

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You want to import into a database, but the attachment is an Excel file - which are you using - MS Access or MS Excel?

    Complicating the issue is the fact that a) not all questions are answered and b) the answers are of different data types.

    Can you post an example of a real data file, and tell us what you want to extract from it? If you are using a database, a description of its structure would help.

    John

  4. #4
    robert315 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    3
    Each file will be a separate record.
    There will be 3-4 different types of files, all with different line numbers...most will be the same line numbers, with only a dozen files different. I am confident I can import similar files by file name.
    Header is always the same structure.
    Only 1 line does not have question mark, it has a colon (.

  5. #5
    robert315 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    3
    John_G wrote:

    You want to import into a database, but the attachment is an Excel file - which are you using - MS Access or MS Excel?

    Attachment was an example of delineated output, not input.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I gave you pseudocode example. Use it and other examples you have reviewed to write procedure specific to your data. Post code for analysis if encounter issue. Review link at bottom of my post for debug techniques.
    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.

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

Similar Threads

  1. Importing Text - Unusual delimiters
    By Jackfam58 in forum Programming
    Replies: 4
    Last Post: 08-07-2012, 06:33 PM
  2. Import Text File
    By vvasudev in forum Import/Export Data
    Replies: 1
    Last Post: 02-17-2012, 01:57 AM
  3. Replies: 5
    Last Post: 12-01-2011, 05:38 PM
  4. Import Text File Size Limit
    By wfbp in forum Import/Export Data
    Replies: 1
    Last Post: 11-04-2010, 09:05 AM
  5. Multiple lines per record: Report?
    By cjbuechler in forum Queries
    Replies: 7
    Last Post: 07-30-2009, 08:32 AM

Tags for this Thread

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