Results 1 to 4 of 4
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    manipulate file before import

    I have a text (fixed length) I would like to manipulate before I import it. Here is what I would like to do:
    • Load a list of values from a table into an array (job codes)
    • Read each record in the file and if it doesnt start with a 1 ignore or remove it
    • Read each line in the file and look for a specific job code (in the array) that will sit in Chars 163 - 167 and if it is one of the numbers in the array create a new file called import2
    • If the job code is not in the array leave it in the original file ( or create new file called import1)


    Now for the reason why:
    I need to import this fixed length file but always at the end are several records that start with a number other than 1 that I dont want.
    In addition, if the record (or line) has a job code that is for wheels then the import specification changes for characters 169 - 222.
    I thought about pulling it all in, then using queries to separate the data, then using some kind of string length formula to change the data but the above method seems cleaner.

    Does any one have an suggestions on how to do this and / or any recommendations on a better process?


    Thanks

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would use VBA and "Line Input" statements.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Building on (and agreeing with) what RuralGuy said, there are two methods. I use the 'old school' method; here is a snipped of code:
    Code:
       '  open error text file - output
       EF = FreeFile
       FileToWrite = CurrentProject.Path & "\ERRORS_" & BaseName & " - ImportHours" & ".txt"
       Me.txtErrFile = FileToWrite
       Open FileToWrite For Output As #EF
    This opens a text file for output. The code to open a text file for input is a little different.


    The second method is using the "FileSystemObject". I am starting to transition to it.
    Here are some links to help you get started.

    Main page : http://www.wiseowl.co.uk/blog/s211/textstream.htm
    First page : http://www.wiseowl.co.uk/blog/s210/filesystemobject.htm
    Second page : http://www.wiseowl.co.uk/blog/s211/writeline.htm
    Third page : http://www.wiseowl.co.uk/blog/s211/readline.htm


    If you get stuck or have questions, post back...

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I agree with Allan/RG.

    Another approach is to
    a) create a table with the structure you want as final result.
    b) create a table with 1 field (if record length is <255), use 2 fields if >255 etc
    c) use table in b) as your working table
    -- delete any records that don't start with 1 to remove the
    always at the end are several records that start with a number other than 1 that I dont want.
    d) use queries or procedures to parse the data and move it to your "final table" as needed.

    I'd still go with "Line Input". Your mentioning of arrays makes me think you might be a Fortran programmer (or familiar with vba). You could put your job codes in a table and work with queries against your working table.

    Good luck with your project, let us know how it goes.

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

Similar Threads

  1. Import Excel file based on a date and time in file name
    By nhylan in forum Import/Export Data
    Replies: 4
    Last Post: 04-16-2013, 03:26 PM
  2. Using VBA to manipulate properties in a Report
    By adacpt in forum Programming
    Replies: 1
    Last Post: 11-26-2012, 09:22 PM
  3. 2-questions regarding data manipulate date:
    By djclntn in forum Queries
    Replies: 6
    Last Post: 08-12-2012, 12:29 PM
  4. Replies: 2
    Last Post: 08-20-2009, 07:53 AM
  5. Manipulate DB through VB ...
    By Zoroxeus in forum Programming
    Replies: 2
    Last Post: 12-18-2005, 01:16 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