Import complex text file into Access

I just confirmed with the user, it is an end of record line.
 
If that text file would have the record (citation) in each line and with delimiter, then this would be one line code, maybe few. But this complex text, I have no idea! :)
 
If it had a fixed number of fields in each record, one line per record, no line breaks, consistent field names ... and I can go on... it would be much easier :)
 
But what I’m good with; I can read the code and follow it, and learn a lot from it.
 
The one Uncle Gizmo sent, it was easy to read, because it has comments. When I write a code I don’t put comments, I’m lazy on comments. :)
 
It's absolutely necessary to comment code especially when you're done with it.

I believe the file attached (Access 2000) should do it. I didn't have time for any fancy forms so just open the module and run the function called TransposeFile from the Immediate Window:
Code:
?TransposeFile("[COLOR="Blue"]Path to file[/COLOR]\Sample.txt")
All the relevant comments are there.

One thing to note is that it transposes the text file to an Excel sheet and the reason behind that is because it allows users to scrutinise the file and make corrections (if necessary) before exporting to db.
So if you want to export directly to the db you can implement that. Or if you want to export the transformed spreadsheet, you can also implement that. All the necessary functions are there for you to use and make slight adjustments.

It's now in your hands and yours to manage.
 

Attachments

I just had to delete that post because yours wasn't there anymore.

Let's see how you get on tomorrow.
 
I found the problem, the new sample text has an extra "Language" in it:-

Code:
ID	SectionName	LineCurrCitation	fCounter	LineStart	LineEnd
4677	Abstract  1 ---------------- 7 ---------------- 11	 ---------------- 10
4678	Language	1 ---------------- 7 ---------------- 12 ---------------- 13
4679	Language	18 ---------------- 1 ---------------- 15 ---------------- 17
4680	Citation	18 ---------------- 2 ---------------- 19 ---------------- 18

So it looked wrong, however I worked through it and it makes sense.

Now it needs code to concatenate the lines as identified by "LineStart" and "LineEnd" and then add them to the correct field in the table.

I still need to figure out the end, as the "LineStart" and "LineEnd" values are wrong for the last Author:-

Code:
ID	SectionName	LineCurrCitation	fCounter	LineStart	LineEnd
3224	Abstract ------------- 906 --------------- 3 --------------- 916 --------------- 915
3225	Author --------------- 906 --------------- 7 --------------- 917 --------------- 918
3226	END ------------------- 0 ---------------- 0 --------------- 920 --------------- 920
 

Attachments

Last edited:
I found the problem, the new sample text has an extra "Language" in it:-

Code:
ID	SectionName	LineCurrCitation	fCounter	LineStart	LineEnd
4677	Abstract  1 ---------------- 7 ---------------- 11	 ---------------- 10
4678	Language	1 ---------------- 7 ---------------- 12 ---------------- 13
4679	Language	18 ---------------- 1 ---------------- 15 ---------------- 17
4680	Citation	18 ---------------- 2 ---------------- 19 ---------------- 18

So it looked wrong, however I worked through it and it makes sense.
Where's the extra Language field coming from Tony?
 
Here:- (line 11) Original studies in any language were searched from MEDLINE database,
 
I see. It shouldn't have been a problem though since it's way over there.
 
I see. It shouldn't have been a problem though since it's way over there.

It is for my code 'cause it looks for it in the whole line...

Might need a slight modification!
 
Oh ok. Do you really use those line numbers you created?
 
It's absolutely necessary to comment code especially when you're done with it.

I believe the file attached (Access 2000) should do it. I didn't have time for any fancy forms so just open the module and run the function called TransposeFile from the Immediate Window:
Code:
?TransposeFile("[COLOR="Blue"]Path to file[/COLOR]\Sample.txt")
All the relevant comments are there.

One thing to note is that it transposes the text file to an Excel sheet and the reason behind that is because it allows users to scrutinise the file and make corrections (if necessary) before exporting to db.
So if you want to export directly to the db you can implement that. Or if you want to export the transformed spreadsheet, you can also implement that. All the necessary functions are there for you to use and make slight adjustments.

It's now in your hands and yours to manage.

WOW, works like a champ! I thought we go to plan B, but this way is way better. One think. I know I'm asking to much. Can you change it, so it's saves in database. I tried to change it, I'm getting lost. This way I'll make this table as temperately, so the user can make corrections to data and then click submit button. I'm trying to reduce steps for the user. I'll do all this, all I need is Transpose data in the same database. But rest of it is amazing, it will take some time to understand it! Thank you very much!
 
One think. I know I'm asking to much. Can you change it, so it's saves in database. I tried to change it, I'm getting lost. ...it will take some time to understand it!
Like I said, it's in your hands now so "take some time to understand it" and add the extra layer of functionality. You did say "I can read the code and follow it, and learn a lot from it" and "Once I get code working, rest of it I can do it myself." so get coding.
 
You right, i should try it.
Thank you very much all for your help!
 
Give it some good thought you'll get it working in no time. All the field names and functions are there ;)

Uncle Gizmo might have something for you too.
 
One more question.
Once its transfer to the spreadsheet, why is Citation filed is blank? Is it supposed to be like this so user can add?
 

Users who are viewing this thread

Back
Top Bottom