input line

mims

Registered User.
Local time
Today, 06:13
Joined
Jul 30, 2011
Messages
10
Hi,

I am using VBA code to upload a text file into an MS Access table (see code below). Everything is working fine, but the first line of the file is not being uploaded. It imports line 2 onwards. Does anyone have any ideas why?

Function Upload_SAP_AGR_USERS4()
Dim F As Long, sLine As String, A(0 To 8) As String
Dim db As Database, rs As Recordset
F = FreeFile
Open "C:\Users\Mims\Desktop\SAP_AGR_USERS4.txt" For Input As F


Line Input #F, sLine
Set db = CurrentDb
Set rs = db.OpenRecordset("dbo_Table_4")

Do While Not EOF(F)
Line Input #F, sLine

ParseToArray sLine, A()
rs.AddNew

rs(0) = A(0)
rs(1) = A(1)
rs(2) = A(2)
rs(3) = A(3)
rs(4) = A(4)
rs(5) = A(5)
rs(6) = A(6)
rs(7) = A(7)
rs(8) = A(8)
rs.Update

Loop
rs.Close
db.Close
Close #F
End Function
 
only thing i can think of, is that there is a data problem, and the first record is getting rejected - but i think you would get an error message

why not put a msgbox in to show you the data eg msgbox sline - or set a breakpoint, and step through the code
 
hi, thanks for your reply. There does not seem to be a problem with the first row of data, because if i put a blank line in the first row then it is picked up correctly. Its seems that the file is only being read from the 2nd row of the text file downwards. Any idea why this could be? i am thinking maybe something to do with thinking the first row is the header names?

Thanks for your help!
 
i can see now

you have line input twice, once before you open the recordset, and then again within the loop - so you ARE losing the first line

justr get rid of the extra line input
 
thank you SO much! its working perfectly now!!! really appreciate your help - it has saved me hours and a lot of frustration. :)
 
I need a input mask for Column ID's within a building. They are Printed like this;
3 W1 N15 or 3 W15 N21

I want all the spaces to be in field and the numbers after the letter can be two or one characters. PLEASE HELP
 
Input Masks

I need an input mask to restrict what users enter for Column ID within a building. For instance:

3 W1 N10 or 3 W10 N1

3 is the Floor, W1 N10 or W10 N1 are the actual columns.


I want all the spaces and capitals show just like my example.

!0\ >L09\ >L09;;_ is whay I am using today and it doesn't work properly.


Please help.
 
#6 & #7 don't hijack someone else's thread but start your own
 

Users who are viewing this thread

Back
Top Bottom