Read a file and import its data into a table

yes BluIshDan, its not a formatted data. would take a hell lot of time to do things the way i want.
 
So you need to learn how to code in VBA to get this done, I can and will guide you thru it but since you are going to have to support and maintain it.... I could write you the code, but how will you maintain it?

The KEY is that you have to start somewhere, that start is back in the link I posted a while ago..... start walking by reading the complete file into one big table....
Once you do/done that, you can take the next step of extracting only the data you want / need. You know how to read the file already, ultimately it would be quite easy for you... but you need to take the step(s)
 
Ok sounds like an inspiration. Well, i did go through the link. The Microsoft tutorial, rite !

If you could write the code i could start learning with what each line meant. Could ask doubts on the way ☺️. So how different is vb from vb.net
 
Reading the file already, not really. Some thing here and there.
 
anishkgt,

I recommend you do some reading and write some code.
FunctionX vba

You will learn by doing. But start slow and evolve; don't add unnecessary complexity too early!
 
Thanks jdraw. The link seems to be useful. Will go through that.
 
Well not really. That link did shows how to build a project with VB does not show anything about file reading with vb and importing to the database. I guess what am looking for i something really like a big project.
 
Well to start... Try googleing and/or looking at the help for Line Input.

If you google a bit you should be able to find samples
You might find this for example:
http://msdn.microsoft.com/en-us/library/aa243392(v=vs.60).aspx

Did you try starting here?

Really with your knowing of how to read the file, it should NOT be that hard to make.... If you start step by step...

Step 1 is how to read the file completely as one whole file into a table... which is the above link.

Step 2 is of no concern at this point.
 
Its not reading the whole file at once. Its part of each line. Like in the attachment A02 has name of the passenger from character 10 to 30 and similarly on A040 for something else based on the structure.

So the code would be !
Line Input A040, chr10 to chr 20

Is that correct ?
 
No, Line Input reads the whole line into a string like the example does...

First you open the file
Open "TESTFILE" For Input As #1
Then you read the file, line by line into a string variable...
Line Input #1, TextLine ' Read line into variable.

TextLine then should hold the entire line, if you want to jump to step 4 immediately...
You then use If left(textline,x) = "Asomething" then....
x would depend on what defines your line, if it is A12, then obviously x would be 3
To find out what line you are at and use functions like Left, Right and Mid to extract the information you need from the line ....
 
Can u send me the above done in the actual code. Like dim ......etc
 
so far this is what i've got and it reads each line and displays in a msgbox

Dim TextLine As String
FileOpen(1, "c:\test.txt", OpenMode.Input)
While Not EOF(1)
TextLine = LineInput(1)
MsgBox(TextLine)
End While
FileClose(1)

where do i add the LineImput# statement and the character to count
 
That isnt vba, perhaps its vb?
But why use VB if you want to be using access? Do you have a complete VB project?
 
Oh i c. vb or vba. Wouldn't i able to get what i what i want ? This would run externally as a exe app. For importing data to the access table.
 
sure you can do what you want just as well in VB as you can in VBA...

Though my experience with VB is very limited but I can try and guide you thru it from my VBA experience.
This link will show you how to access the database/table
http://support.microsoft.com/kb/148361
 

Users who are viewing this thread

Back
Top Bottom