Hi all,
I have been trying to do this for a month now. I am required to import a text file (ranging from 500000 to 3000000 lines) into an access table. I managed code a function that will import the file, however, the file is not in the right order. There are certain rows that are jumbled up. E.g. Row 123 of the text file is input into record number 321.
I need the file to be imported in that specific order as I have other functions that will be working with the data to extract certain information.
These are the current codes that I am using:
How do I make sure that the text file is imported in the right order?
I have been trying to do this for a month now. I am required to import a text file (ranging from 500000 to 3000000 lines) into an access table. I managed code a function that will import the file, however, the file is not in the right order. There are certain rows that are jumbled up. E.g. Row 123 of the text file is input into record number 321.
I need the file to be imported in that specific order as I have other functions that will be working with the data to extract certain information.
These are the current codes that I am using:
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
If IsNull(Me.txtImport) Then
MsgBox "You forgot to select a file."
Else
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 "The file has been imported."
End If
End Sub
How do I make sure that the text file is imported in the right order?