I have found a few threads on this, but the code is difficult for me to follow. Most of the time I have no idea where to put it. I'm taking VB courses but it's not at the point where my project at work requires me to be, so I'm kind of on my own here.
I have a project and a form. The form has two buttons. I got one to work (yay). The other button takes a csv file (LVImport.csv) and imports it into Access. I can't get the code to work. The code I copied has this statement:
NumOfRecords = LOF(1) / 132 ' Record size
I don't know where the 132 comes from or how to find what my number should be. The same number of fields exist in the file but the number of records varies.
Can you please help me with this code and tell me exactly where I need to put it?
Private Sub btnLVImport_Click()
{declared variables}
{Connection string information}
Open "c:\LVImport.csv" For Binary Access Read As #1
NumOfRecords = LOF(1) / 132 ' Record size
Do
Counter = Counter + 1
' Displays counter in label on the main screen
' so the user can see something is happening
Label1.Caption = "Records Imported = " & CStr(Counter)
DoEvents
' Reads and stores the text data into the database table
Get #1, , ImportRec
conn.Execute "INSERT INTO LV_Datalog yadda yadda
Loop Until Counter = NumOfRecords
' Closes and destroys objects
conn.Close
Set conn = Nothing
Close #1
' Prompts the user processing has completed
MsgBox "Done!", vbInformation
End Sub
Thanks!
Barb E.
I have a project and a form. The form has two buttons. I got one to work (yay). The other button takes a csv file (LVImport.csv) and imports it into Access. I can't get the code to work. The code I copied has this statement:
NumOfRecords = LOF(1) / 132 ' Record size
I don't know where the 132 comes from or how to find what my number should be. The same number of fields exist in the file but the number of records varies.
Can you please help me with this code and tell me exactly where I need to put it?
Private Sub btnLVImport_Click()
{declared variables}
{Connection string information}
Open "c:\LVImport.csv" For Binary Access Read As #1
NumOfRecords = LOF(1) / 132 ' Record size
Do
Counter = Counter + 1
' Displays counter in label on the main screen
' so the user can see something is happening
Label1.Caption = "Records Imported = " & CStr(Counter)
DoEvents
' Reads and stores the text data into the database table
Get #1, , ImportRec
conn.Execute "INSERT INTO LV_Datalog yadda yadda
Loop Until Counter = NumOfRecords
' Closes and destroys objects
conn.Close
Set conn = Nothing
Close #1
' Prompts the user processing has completed
MsgBox "Done!", vbInformation
End Sub
Thanks!
Barb E.