Hi,
I need to insert many records into Access table. I create records by building various combinations of the fields. The number of the combinations (the records to be inserted) is 362208. It takes long time to insert all of them one by one.
I am wondering if it's possible to insert entire "recordset" for all combinatoins in a single Insert.
Thank you
vladk
This is the the code I use for now (very slow):
...
Dim objStatesDic As New Dictionary
Dim objProgDic As New Dictionary
Dim objCoverageDic As New Dictionary
Dim objExposureDic As New Dictionary
Dim objQuarterDateDic As New Dictionary
....
'Here I load my dictionaries ...
....
'Here I run nested loops for all combinations:
For Each varStateKey In objStatesDic
For Each varProgKey In objProgDic
For Each varCoverageKey In objCoverageDic
For Each varExposureKey In objExposureDic
For Each varQuarterDateKey In objQuarterDateDic
ExecuteSQLDDL "INSERT INTO " & pstrTable & " VALUES (" & "'" & objStatesDic.Item(varStateKey) & "'" & ", " & _
"'" & objProgDic.Item(varProgKey) & "'" & ", " & _
"'" & objCoverageDic.Item(varCoverageKey) & "'" & ", " & _
"'" & objExposureDic.Item(varExposureKey) & "'" & ", " & _
"#" & objQuarterDateDic.Item(varQuarterDateKey) & "#" & ", " & _
0 & ");"
Next varQuarterDateKey
Next varExposureKey
Next varCoverageKey
Next varProgKey
Next varStateKey
....
Public Sub ExecuteSQLDDL(ByVal pstrSQLString As String)
Const METHOD_NAME As String = "ExecuteSQLDDL"
On Error GoTo MethodExit
Dim objDB As DAO.Database
Dim objQD As DAO.QueryDef
Set objDB = DBEngine.Workspaces(0).Databases(0)
Set objQD = objDB.CreateQueryDef("")
objQD.SQL = pstrSQLString
objQD.Execute
objDB.Close
MethodExit:
If Err.Number <> 0 Then
MsgBox "Error " & CStr(Err.Number) & " in " & METHOD_NAME & vbCr & Err.Description
End If
End Sub
I need to insert many records into Access table. I create records by building various combinations of the fields. The number of the combinations (the records to be inserted) is 362208. It takes long time to insert all of them one by one.
I am wondering if it's possible to insert entire "recordset" for all combinatoins in a single Insert.
Thank you
vladk
This is the the code I use for now (very slow):
...
Dim objStatesDic As New Dictionary
Dim objProgDic As New Dictionary
Dim objCoverageDic As New Dictionary
Dim objExposureDic As New Dictionary
Dim objQuarterDateDic As New Dictionary
....
'Here I load my dictionaries ...
....
'Here I run nested loops for all combinations:
For Each varStateKey In objStatesDic
For Each varProgKey In objProgDic
For Each varCoverageKey In objCoverageDic
For Each varExposureKey In objExposureDic
For Each varQuarterDateKey In objQuarterDateDic
ExecuteSQLDDL "INSERT INTO " & pstrTable & " VALUES (" & "'" & objStatesDic.Item(varStateKey) & "'" & ", " & _
"'" & objProgDic.Item(varProgKey) & "'" & ", " & _
"'" & objCoverageDic.Item(varCoverageKey) & "'" & ", " & _
"'" & objExposureDic.Item(varExposureKey) & "'" & ", " & _
"#" & objQuarterDateDic.Item(varQuarterDateKey) & "#" & ", " & _
0 & ");"
Next varQuarterDateKey
Next varExposureKey
Next varCoverageKey
Next varProgKey
Next varStateKey
....
Public Sub ExecuteSQLDDL(ByVal pstrSQLString As String)
Const METHOD_NAME As String = "ExecuteSQLDDL"
On Error GoTo MethodExit
Dim objDB As DAO.Database
Dim objQD As DAO.QueryDef
Set objDB = DBEngine.Workspaces(0).Databases(0)
Set objQD = objDB.CreateQueryDef("")
objQD.SQL = pstrSQLString
objQD.Execute
objDB.Close
MethodExit:
If Err.Number <> 0 Then
MsgBox "Error " & CStr(Err.Number) & " in " & METHOD_NAME & vbCr & Err.Description
End If
End Sub