UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Splitting a text file before import    
 
   
danmc18
post Aug 23 2004, 11:09 AM
Post #1

UtterAccess Member
Posts: 30



Good afternoon,
I have a text file which i want to import into a table, it is made up of 3 lines; 1st line is supplier address - 2nd line is the order - 3rd line is customer address. each line needs a different import specification. does anyone know of a way to pull this text file into access?

cheers
dan
Go to the top of the page
 
+
curtswanson
post Aug 23 2004, 11:54 AM
Post #2

UtterAccess Enthusiast
Posts: 66



The sub below will take the three line file "Input.txt" and split it into "Input1.txt", "Input2.txt", "Input3.txt".

Sub SplitText()
Const myPath = "C:\My Stuff\"
Const myInFile = "InputFile"
Const myFileType = ".txt"
Dim i As Integer
Dim inputline As String

Open myPath & myInFile & myFileType For Input As #1
For i = 1 To 3
Line Input #1, inputline
Open myPath & myInFile & i & myFileType For Output As #2
Print #2, inputline
Close #2
Next i
Close #1
End Sub
Go to the top of the page
 
+
danmc18
post Aug 23 2004, 12:01 PM
Post #3

UtterAccess Member
Posts: 30



thats excellent mate, thanks very much. is it possible for these files to be removed once the import has completed?

dan
Go to the top of the page
 
+
curtswanson
post Aug 23 2004, 12:05 PM
Post #4

UtterAccess Enthusiast
Posts: 66



You're welcome.

Sub KillMyFiles()
dim i as integer
for i = 1 to 3
kill myPath & myInFile & i & myFileType
next i
end sub

Use the same constants as previous.
Go to the top of the page
 
+
danmc18
post Sep 2 2004, 09:23 AM
Post #5

UtterAccess Member
Posts: 30



Alright mate, thanks for the previous help. i've got another question for you. i need to export to a file made up of three separate exports ie three text files which need to be made into one file, and given a filename of the current date and time (ddmmyyyyhhmm). pretty much my initial problem except the other way around

any ideas?
dan
Go to the top of the page
 
+
Clippit
post Sep 3 2004, 10:09 PM
Post #6

UtterAccess VIP
Posts: 3,645
From: Near Toronto, ON, CA



How do the records in the output need to be sequenced? How do they need to be formatted. Rather than doing htree exports and interleaving the records (the opposite of the solution above) you ,ay be better to do the export via code, where you could write out the records just the way you want to. There is a sample of this approach at this link.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 25th May 2013 - 01:48 AM