Hi all,
I'm currently facing an issue with my codes. I am required to import a text file line by line into access, however, when I check the number of records in Access, it does not match the number of lines in the text file.
E.g. My text file may have 519420 lines of text, but my records only show 518785.
I need my entire text file to be imported line by line in the exact order.
This is my current import code:
Code:
Private Sub Command3_Click()
Dim fs As Object
Dim filename As String
Dim tsIn As Object
Dim sFileIn As String
Dim Text As String
Dim sqlcre As String
Dim sqlsta As String
sFileIn = Me.txtImport
Set fs = CreateObject("Scripting.FileSystemObject")
Set tsIn = fs.OpenTextFile(sFileIn, 1)
While Not tsIn.AtEndOfStream
tmps = tsIn.ReadLine
sqlsta = "INSERT INTO Table1(Field1) VALUES ('" & Replace(tmps, "'", "''") & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlsta
Wend
DoCmd.SetWarnings True
MsgBox "Finished."
End Sub