Avatar of Easty
Easty

asked on 

importing a csv in to a table. Recognising line breaks

I want to insert values from a csv file in to a table.
Im having trouble in recognising an EOL character
When i try and insert buffer(2) which is the last field i insert, it also has the date from the next line so the program isnt recognising when the 1st line is finished and the 2nd line has started

From the code i am also going through the code charachter by charater is there an easy way to go through line by line.

Open MyPathFile For Input As #1
               
                Do While Not EOF(1)
                     Do While MyChar <> vbLf
                     MyChar = Input(1, #1)
                     DataIn = DataIn + MyChar
                    Loop
                     buffer = Split(DataIn, ",")
               
                        DoCmd.RunSQL "INSERT INTO tlbTrans (DateOfTrans, PayeeName, Amount) " + _
                                    "VALUES ('" & buffer(0) & "','" & buffer(1) & "'," & buffer(2) & ")"
Microsoft Access

Avatar of undefined
Last Comment
Easty
ASKER CERTIFIED SOLUTION
Avatar of stevbe
stevbe

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Why don't you just link to it? You can run a make table query after that. Is there a reason you're trying to use code for this?
J
Avatar of Easty
Easty

ASKER

I have to do a number of calculations on the data before it goes in to the table.
Does this affect a make-table query? I have never used 1 before.
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Are you can you not perform those calculations on a linked table?
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

Go go the file menu and use the Get external data option. Select Link Tables. Go out and find your CSV file. Link it.
It will now be a resident table in your DB that you can perform any kind of calculations you want through code or query an write to a Permanent table.
Avatar of Easty
Easty

ASKER

I want to do the calculations on the data before i insert it in to the table.
otherwise i will be doing the calculations at run time.

Thanks
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo