shawnntjr
02-02-2015, 02:22 AM
Hi all,
I am in need of serious help. I have a problem that's been bugging me for quite some time 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:
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 can I ensure that the file has been imported in the exact same order as it was in the text file? Any help would be greatly appreciated!
I am in need of serious help. I have a problem that's been bugging me for quite some time 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:
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 can I ensure that the file has been imported in the exact same order as it was in the text file? Any help would be greatly appreciated!