Mike_10
New member
- Local time
- Today, 17:03
- Joined
- Jul 29, 2020
- Messages
- 18
Hello, I have done hours of combing the web trying to solve this problem myself but still can't find anything to help. I am not experienced in any type of coding and am trying to teach myself some of the Access VBA coding basics.
I have a large text file (590,352 KB) that consist of about 1.1 million records, all in 1 field. Each record contains 534 characters. I am trying to break this into an organized recordset of 41 fields, each of varying string lengths. For testing purposes I created 4 smaller sample files (15 KB, 263 KB, 3,657 KB, and 49,044 KB) of the original, thus I can check for code functionality and performance. I have successfully accomplished building the "organized' recordset with all sample files (and the rest of the code runs great), but am receiving the out of memory error when I ramp all the way up to the full burden of the original file.
Below is the relevant portion of the code. The debugger highlights ".AddNew" inside the With MasterRS statement. How should I build this recordset?
EDIT by Isladogs - Added code tags
I have a large text file (590,352 KB) that consist of about 1.1 million records, all in 1 field. Each record contains 534 characters. I am trying to break this into an organized recordset of 41 fields, each of varying string lengths. For testing purposes I created 4 smaller sample files (15 KB, 263 KB, 3,657 KB, and 49,044 KB) of the original, thus I can check for code functionality and performance. I have successfully accomplished building the "organized' recordset with all sample files (and the rest of the code runs great), but am receiving the out of memory error when I ramp all the way up to the full burden of the original file.
Below is the relevant portion of the code. The debugger highlights ".AddNew" inside the With MasterRS statement. How should I build this recordset?
Code:
Public PRecordCount As Long
Dim strSQL As String
Dim db As DAO.Database
Dim ImportedDataRS As DAO.Recordset
Dim MasterRS As ADODB.Recordset
Dim MasterField(50) As String
Dim FieldCount As Integer
strSQL = "SELECT * FROM [" & NewFileName & "]"
Set db = OpenDatabase(NewPathName, False, True, "Text; HDR=No")
Set ImportedDataRS = db.OpenRecordset(strSQL)
MasterField(1) = "ACCOUNT"
MasterField(2) = "YEAR"
MasterField(3) = "JURISDICTION"
MasterField(4) = "TAX UNIT ACCT"
MasterField(5) = "LEVY"
MasterField(6) = "HOMESTEAD"
MasterField(7) = "OVER 65"
MasterField(8) = "VETERAN"
MasterField(9) = "DISABLED"
MasterField(10) = "AG"
MasterField(11) = "DATE PAID"
MasterField(12) = "DUE DATE"
MasterField(13) = "OMIT"
MasterField(14) = "LEVY BALANCE"
MasterField(15) = "SUIT"
MasterField(16) = "CAUSE NO"
MasterField(17) = "BANK CODE"
MasterField(18) = "BANKRUPT NO"
MasterField(19) = "ATTORNEY"
MasterField(20) = "COURT COST"
MasterField(21) = "ABSTRACT FEE"
MasterField(22) = "DEFERRAL"
MasterField(23) = "BILL SUPP"
MasterField(24) = "SPLIT PMT"
MasterField(25) = "CATEGORY"
MasterField(26) = "OWNER 1"
MasterField(27) = "OWNER 2"
MasterField(28) = "MAILING ADDRESS 1"
MasterField(29) = "MAILING ADDRESS 2"
MasterField(30) = "MAILING CITY"
MasterField(31) = "MAILING STATE"
MasterField(32) = "MAILING ZIP"
MasterField(33) = "ROLL CODE"
MasterField(34) = "PARCEL NO"
MasterField(35) = "PARCEL NAME"
MasterField(36) = "PAYMENT AGREEMENT"
MasterField(37) = "AMT DUE AS OF EOM"
MasterField(38) = "AMT DUE +30 DAYS"
MasterField(39) = "AMT DUE +60 DAYS"
MasterField(40) = "AMT DUE +90 DAYS"
MasterField(41) = "AMOUNT INDICATOR"
FieldCount = 41
'Set up an in-memory recordset that will assign fields to all the imported data
Set MasterRS = New ADODB.Recordset
For i = 1 To FieldCount
MasterRS.Fields.Append MasterField(i), adVarChar, 40, adFldMayBeNull
Next i
'Set up the in-memory recordset with assigned field names to separate out and organize all single field raw data
i = 1
ImportedDataRS.MoveFirst
MasterRS.Open
Do While Not ImportedDataRS.EOF
With MasterRS
.AddNew
.Fields("ACCOUNT") = Mid(ImportedDataRS.Fields(0), 1, 34)
.Fields("YEAR") = Mid(ImportedDataRS.Fields(0), 35, 4)
.Fields("JURISDICTION") = Mid(ImportedDataRS.Fields(0), 39, 4)
.Fields("TAX UNIT ACCT") = Mid(ImportedDataRS.Fields(0), 43, 34)
.Fields("LEVY") = Mid(ImportedDataRS.Fields(0), 77, 11)
.Fields("HOMESTEAD") = Mid(ImportedDataRS.Fields(0), 88, 1)
.Fields("OVER 65") = Mid(ImportedDataRS.Fields(0), 89, 1)
.Fields("VETERAN") = Mid(ImportedDataRS.Fields(0), 90, 1)
.Fields("DISABLED") = Mid(ImportedDataRS.Fields(0), 91, 1)
.Fields("AG") = Mid(ImportedDataRS.Fields(0), 92, 1)
.Fields("DATE PAID") = Mid(ImportedDataRS.Fields(0), 93, 8)
.Fields("DUE DATE") = Mid(ImportedDataRS.Fields(0), 101, 8)
.Fields("OMIT") = Mid(ImportedDataRS.Fields(0), 109, 2)
.Fields("LEVY BALANCE") = Mid(ImportedDataRS.Fields(0), 111, 11)
.Fields("SUIT") = Mid(ImportedDataRS.Fields(0), 122, 1)
.Fields("CAUSE NO") = Mid(ImportedDataRS.Fields(0), 123, 40)
.Fields("BANK CODE") = Mid(ImportedDataRS.Fields(0), 163, 1)
.Fields("BANKRUPT NO") = Mid(ImportedDataRS.Fields(0), 164, 40)
.Fields("ATTORNEY") = Mid(ImportedDataRS.Fields(0), 204, 1)
.Fields("COURT COST") = Mid(ImportedDataRS.Fields(0), 205, 7)
.Fields("ABSTRACT FEE") = Mid(ImportedDataRS.Fields(0), 212, 7)
.Fields("DEFERRAL") = Mid(ImportedDataRS.Fields(0), 219, 1)
.Fields("BILL SUPP") = Mid(ImportedDataRS.Fields(0), 220, 1)
.Fields("SPLIT PMT") = Mid(ImportedDataRS.Fields(0), 221, 1)
.Fields("CATEGORY") = Mid(ImportedDataRS.Fields(0), 222, 4)
.Fields("OWNER 1") = Mid(ImportedDataRS.Fields(0), 226, 40)
.Fields("OWNER 2") = Mid(ImportedDataRS.Fields(0), 266, 40)
.Fields("MAILING ADDRESS 1") = Mid(ImportedDataRS.Fields(0), 306, 40)
.Fields("MAILING ADDRESS 2") = Mid(ImportedDataRS.Fields(0), 346, 40)
.Fields("MAILING CITY") = Mid(ImportedDataRS.Fields(0), 386, 40)
.Fields("MAILING STATE") = Mid(ImportedDataRS.Fields(0), 426, 2)
.Fields("MAILING ZIP") = Mid(ImportedDataRS.Fields(0), 428, 12)
.Fields("ROLL CODE") = Mid(ImportedDataRS.Fields(0), 440, 1)
.Fields("PARCEL NO") = Mid(ImportedDataRS.Fields(0), 441, 8)
.Fields("PARCEL NAME") = Mid(ImportedDataRS.Fields(0), 449, 40)
.Fields("PAYMENT AGREEMENT") = Mid(ImportedDataRS.Fields(0), 489, 1)
.Fields("AMT DUE AS OF EOM") = Mid(ImportedDataRS.Fields(0), 490, 11)
.Fields("AMT DUE +30 DAYS") = Mid(ImportedDataRS.Fields(0), 501, 11)
.Fields("AMT DUE +60 DAYS") = Mid(ImportedDataRS.Fields(0), 512, 11)
.Fields("AMT DUE +90 DAYS") = Mid(ImportedDataRS.Fields(0), 523, 11)
.Fields("AMOUNT INDICATOR") = Mid(ImportedDataRS.Fields(0), 534, 1)
.Update
End With
ImportedDataRS.MoveNext
i = i + 1
Loop
PRecordCount = i - 1
ImportedDataRS.Close
MasterRS.Close
Set ImportedDataRS = Nothing
Set MasterRS = Nothing
Set db = Nothing
EDIT by Isladogs - Added code tags
Last edited: