dwhawley
Jul 19th, 2000, 12:42 PM
vb gurus,
i am trying to create an application that will import a text file and then parse the information into a table. i'm using vb6 and ado 2.1. my thought was to create a connection to the file and then opening it into a recordset. i added a messagebox that gives me the the recordcount and absoluteposition of the recordset though i cannot figure out where it is getting its values (absoluteposition = -1 and recordcount = 145). though this approach does not seem to be working, it still should be a viable way to go. any help would be greatly appreciated. i attached my code below.
Public Sub Parse()
'create a counter
Dim i As Integer
i = 1
'reformat common dialog box
cdlBics2.Enabled = True
cdlBics2.Filter = "*.dat"
cdlBics2.FileName = "*.dat"
cdlBics2.Value = 1
cdlBics2.DialogTitle = "Select Print File"
strFile = cdlBics2.FileName
'copy file selected above to print.txt
FileCopy strFile, "m:\sleeping bear\print.txt"
'-----------------------------------------------------------
'establish a connection to print.txt and create a
'recordset
Dim strConPrint As String
Dim conPrint As New ADODB.Connection
strConPrint = "Provider=MSDASQL;" & _
"Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"DBQ=m:\sleeping bear"
conPrint.Open strConPrint
Set rsPackingSlip0 = New ADODB.Recordset
rsPackingSlip0.Open "print.txt", conPrint, adOpenStatic, adLockReadOnly
'-----------------------------------------------------------
'-----------------------------------------------------------
'this block of code is temporary. it allows me to see that
'everything is going ok (or more accurately, not going ok)
With rsPackingSlip0
If rsPackingSlip0.EOF = True And rsPackingSlip0.BOF = True Then
MsgBox "Empty"
Else
MsgBox "recordcount = " & .RecordCount & vbCrLf & _
"position = " & .AbsolutePosition & vbCrLf
End If
End With
'-----------------------------------------------------------
'create new recordset that will take the info from the
'previous recordset and parse it to the new table.
sqlPackingSlip1 = "SELECT * FROM tblPackingSlip1"
Set rsPackingSlip1 = New ADODB.Recordset
rsPackingSlip1.Open sqlPackingSlip1, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Do Until i = 0
rsPackingSlip1.AddNew
rsPackingSlip1.Fields(0) = ParseString & _
(rsPackingSlip0.Fields(0), "Pag Custome ", i)
rsPackingSlip1.Update
i = i + 1
Loop
End Sub
i am trying to create an application that will import a text file and then parse the information into a table. i'm using vb6 and ado 2.1. my thought was to create a connection to the file and then opening it into a recordset. i added a messagebox that gives me the the recordcount and absoluteposition of the recordset though i cannot figure out where it is getting its values (absoluteposition = -1 and recordcount = 145). though this approach does not seem to be working, it still should be a viable way to go. any help would be greatly appreciated. i attached my code below.
Public Sub Parse()
'create a counter
Dim i As Integer
i = 1
'reformat common dialog box
cdlBics2.Enabled = True
cdlBics2.Filter = "*.dat"
cdlBics2.FileName = "*.dat"
cdlBics2.Value = 1
cdlBics2.DialogTitle = "Select Print File"
strFile = cdlBics2.FileName
'copy file selected above to print.txt
FileCopy strFile, "m:\sleeping bear\print.txt"
'-----------------------------------------------------------
'establish a connection to print.txt and create a
'recordset
Dim strConPrint As String
Dim conPrint As New ADODB.Connection
strConPrint = "Provider=MSDASQL;" & _
"Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"DBQ=m:\sleeping bear"
conPrint.Open strConPrint
Set rsPackingSlip0 = New ADODB.Recordset
rsPackingSlip0.Open "print.txt", conPrint, adOpenStatic, adLockReadOnly
'-----------------------------------------------------------
'-----------------------------------------------------------
'this block of code is temporary. it allows me to see that
'everything is going ok (or more accurately, not going ok)
With rsPackingSlip0
If rsPackingSlip0.EOF = True And rsPackingSlip0.BOF = True Then
MsgBox "Empty"
Else
MsgBox "recordcount = " & .RecordCount & vbCrLf & _
"position = " & .AbsolutePosition & vbCrLf
End If
End With
'-----------------------------------------------------------
'create new recordset that will take the info from the
'previous recordset and parse it to the new table.
sqlPackingSlip1 = "SELECT * FROM tblPackingSlip1"
Set rsPackingSlip1 = New ADODB.Recordset
rsPackingSlip1.Open sqlPackingSlip1, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Do Until i = 0
rsPackingSlip1.AddNew
rsPackingSlip1.Fields(0) = ParseString & _
(rsPackingSlip0.Fields(0), "Pag Custome ", i)
rsPackingSlip1.Update
i = i + 1
Loop
End Sub