Context-
I have a text file (.txt) that is comma delimited and has each text field surrounded in “”. It does not contain column headers.
I need to import 50 of the 300 rows so am using code instead of linking or importing (via 'get external data') since it exceeds the 255+ limit. I am building a database in Access 2007 off this file.
I have a table that shows every field number and field name in the text file. I added a Y/N box where I marked the fields I want to import and built a query to show only those fields (QRY_IMPORT). Column [FieldID] is the location and [FieldName] is the name. There are 50 records, so I need [FieldID] = 1,2,61,115,154, 155,166,167, etc…
I would like to allow the flexibility to add fields in the future which is why I am planning on building a new table each time with the selected [FieldName] being the column headers.
Question-
What is the best way to go about this?
Step one, I would think is to build a new table with fields selected in the [FieldName] of QRY_IMPORT
Step two, would be to parse out each line, create a count for what field it’s on, see if that count matches one of the fields that I’m looking for and it so, write it to the table. I have written procedures that go though each line of a query using .MoveNext and could go through each of the 50 records in the query, then loop through the code until it gets to that field, write that field to a table, then move to the next line in the query, etc, but then it would have to cycle through 50 fields or query and text of potentially 4000 rows.
I would appreciate any pointers, examples in any level of detail for how this would be done (expertly, efficiently). If the answer involves arrays, I have never used them and don’t really know how they work (is it time I learn?) :)
I have a text file (.txt) that is comma delimited and has each text field surrounded in “”. It does not contain column headers.
I need to import 50 of the 300 rows so am using code instead of linking or importing (via 'get external data') since it exceeds the 255+ limit. I am building a database in Access 2007 off this file.
I have a table that shows every field number and field name in the text file. I added a Y/N box where I marked the fields I want to import and built a query to show only those fields (QRY_IMPORT). Column [FieldID] is the location and [FieldName] is the name. There are 50 records, so I need [FieldID] = 1,2,61,115,154, 155,166,167, etc…
I would like to allow the flexibility to add fields in the future which is why I am planning on building a new table each time with the selected [FieldName] being the column headers.
Question-
What is the best way to go about this?
Step one, I would think is to build a new table with fields selected in the [FieldName] of QRY_IMPORT
Step two, would be to parse out each line, create a count for what field it’s on, see if that count matches one of the fields that I’m looking for and it so, write it to the table. I have written procedures that go though each line of a query using .MoveNext and could go through each of the 50 records in the query, then loop through the code until it gets to that field, write that field to a table, then move to the next line in the query, etc, but then it would have to cycle through 50 fields or query and text of potentially 4000 rows.
I would appreciate any pointers, examples in any level of detail for how this would be done (expertly, efficiently). If the answer involves arrays, I have never used them and don’t really know how they work (is it time I learn?) :)
Comment