Hello all,
I have a module that imports/parses text files, and inserts their contents into various tables/fields, using a wide variety of logic.
The code does what it's intended to do, without any errors. The problem is that it takes a long time to run the code, and my file size grows out of control. It's taking about 6-8 minutes to insert ~15,000 records into the table.
Additionally, the .accdb file will grow from ~2 MB to well over 100 MB after running the code. If I do a compact and repair, the file size drops back down to about ~4 MB. There must be some inefficiencies in my code that are hogging memory and slowing things down.
The code is basically performing ~15,000 different insert statements as follows (these are all dummy names - some inserts only have 2-3 fields, others have 20-25, and they all go into different tables using all kinds of different logic):
Basically, for each line, it overwrites the SQL statement behind the InsertQuery object in the database, and then executes it. Then it moves on to the next line, and repeats that process over and over.
My hunch is that this is causing the inefficiency issues here. I've learned from this forum that it's important to use parameterized queries, and I like the visual layout of this code, but it may be too slow to actually use.
I've read that it's faster to use CurrentDb.Execute strSQL, dbFailOnError instead, but it seems like it would be pretty tedious/risky/ugly to build a huge concatenated string like that.
Is there a problem with the way I've approached this code, or is there something else that might be causing my performance/memory issues here? I'm happy to answer any other questions that may help shed some light on this here.
Thanks for reading!
I have a module that imports/parses text files, and inserts their contents into various tables/fields, using a wide variety of logic.
The code does what it's intended to do, without any errors. The problem is that it takes a long time to run the code, and my file size grows out of control. It's taking about 6-8 minutes to insert ~15,000 records into the table.
Additionally, the .accdb file will grow from ~2 MB to well over 100 MB after running the code. If I do a compact and repair, the file size drops back down to about ~4 MB. There must be some inefficiencies in my code that are hogging memory and slowing things down.
The code is basically performing ~15,000 different insert statements as follows (these are all dummy names - some inserts only have 2-3 fields, others have 20-25, and they all go into different tables using all kinds of different logic):
Code:
Set db = CurrentDb
Set qdf = db.QueryDefs("InsertQuery") 'Exists in the file already
strSQL = "PARAMETERS RecordNamePar Text, RecordDatePar DateTime, RecordProperty1Par Text, Record Property2Par Text; " & _
"INSERT INTO [Table1] ([record_name_tx], [record_dte], [record_property_1_tx], [record_property_2_tx]) " & _
"VALUES ([RecordNamePar], [RecordDatePar], [RecordProperty1Par], [RecordProperty2Par]);"
qdf.SQL = strSQL
qdf.Parameters("RecordNamePar") = RECORD_NAME 'Variable
qdf.Parameters("RecordDatePar") = RECORD_DATE 'Variable
qdf.Parameters("RecordProperty1Par") = RECORD_PROPERTY_1 'Variable
qdf.Parameters("RecordProperty2Par") = RECORD_PROPERTY_2 'Variable
qdf.Execute
Basically, for each line, it overwrites the SQL statement behind the InsertQuery object in the database, and then executes it. Then it moves on to the next line, and repeats that process over and over.
My hunch is that this is causing the inefficiency issues here. I've learned from this forum that it's important to use parameterized queries, and I like the visual layout of this code, but it may be too slow to actually use.
I've read that it's faster to use CurrentDb.Execute strSQL, dbFailOnError instead, but it seems like it would be pretty tedious/risky/ugly to build a huge concatenated string like that.
Is there a problem with the way I've approached this code, or is there something else that might be causing my performance/memory issues here? I'm happy to answer any other questions that may help shed some light on this here.
Thanks for reading!