1
1scant
I have a rather large Excel file that looks up references in a hug
Access file. The Excel file has about 120,000 rows (2 files of 60,000
and the Access file has about 2.7M records. I have to determine if eac
Ref Doc in column F of the Excel file has a record in the Access file.
This is my first attempt at getting one application to talk t
another.
The problem is, it is pretty slow and I'm hoping someone can point ou
a way to make it much faster. One idea might be to sort the Excel fil
and the Access table on the Ref Doc and do brute force find in a
ever-decreasing size loop. But I'm not savvy enough to tackle tha
right yet.
The code is as follows:
Sub MatchInARMS()
'Application.ScreenUpdating = False
' turning screen updating off optimizes code execution
Dim conADOConnection As New Connection, strConnect As String
Dim strDB, strSQL As String
Dim cmdGetMyData As New Command
Dim rstMyData As Recordset
Dim strRefCell As String
Dim strPrevCell As String
Dim boolPrevStatus As Boolean
'**********************************************
strDB = "C:\Documents and Settings\u00504\Desktop\dc_arms_all.mdb"
'**********************************************
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source = " & strDB
conADOConnection.Open strConnect
' loop to look up each Ref Doc in ARMS
' Starting at F2 and continuing down that column of reference items.
Worksheets("dc_drawing_bad_3").Activate
Worksheets("dc_drawing_bad_3").Range("F2").Activate
strPrevCell = "Nothing"
strPrevValue = "Nothing"
boolPrevStatus = False
For i = 1 To 16008
strRefCell = ActiveCell.Value
'If the previous reference is the same as the new ref, don't do
' the time-consuming DB lookup.
If strRefCell = strPrevCell Then
If boolPrevStatus Then
ActiveCell.Offset(0, 4) = "GOOD"
ActiveCell.Offset(0, 5).Value = strPrevValue
Else
ActiveCell.Offset(0, 4) = "BAD"
End If
Else
strPrevCell = strRefCell
strSQL = "Select * From arms Where [dsn]='" & strRefCell & _
"'ORDER BY status"
With cmdGetMyData
Set .ActiveConnection = conADOConnection
.CommandText = strSQL
.CommandType = adCmdText
End With
Set rstMyData = cmdGetMyData.Execute()
If rstMyData.EOF Then
'MsgBox strRefCell & " BAD "
ActiveCell.Offset(0, 4).Value = "BAD"
boolPrevStatus = False
Else
'MsgBox strRefCell & " GOOD "
ActiveCell.Offset(0, 4).Value = "GOOD"
strPrevValue = rstMyData.Fields(4).Value
ActiveCell.Offset(0, 5).Value = strPrevValue
boolPrevStatus = True
End If
rstMyData.Close
End If
ActiveCell.Offset(1, 0).Activate
Next i
'Application.ScreenUpdating = True
conADOConnection.Close
End Su
Access file. The Excel file has about 120,000 rows (2 files of 60,000
and the Access file has about 2.7M records. I have to determine if eac
Ref Doc in column F of the Excel file has a record in the Access file.
This is my first attempt at getting one application to talk t
another.
The problem is, it is pretty slow and I'm hoping someone can point ou
a way to make it much faster. One idea might be to sort the Excel fil
and the Access table on the Ref Doc and do brute force find in a
ever-decreasing size loop. But I'm not savvy enough to tackle tha
right yet.
The code is as follows:
Sub MatchInARMS()
'Application.ScreenUpdating = False
' turning screen updating off optimizes code execution
Dim conADOConnection As New Connection, strConnect As String
Dim strDB, strSQL As String
Dim cmdGetMyData As New Command
Dim rstMyData As Recordset
Dim strRefCell As String
Dim strPrevCell As String
Dim boolPrevStatus As Boolean
'**********************************************
strDB = "C:\Documents and Settings\u00504\Desktop\dc_arms_all.mdb"
'**********************************************
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source = " & strDB
conADOConnection.Open strConnect
' loop to look up each Ref Doc in ARMS
' Starting at F2 and continuing down that column of reference items.
Worksheets("dc_drawing_bad_3").Activate
Worksheets("dc_drawing_bad_3").Range("F2").Activate
strPrevCell = "Nothing"
strPrevValue = "Nothing"
boolPrevStatus = False
For i = 1 To 16008
strRefCell = ActiveCell.Value
'If the previous reference is the same as the new ref, don't do
' the time-consuming DB lookup.
If strRefCell = strPrevCell Then
If boolPrevStatus Then
ActiveCell.Offset(0, 4) = "GOOD"
ActiveCell.Offset(0, 5).Value = strPrevValue
Else
ActiveCell.Offset(0, 4) = "BAD"
End If
Else
strPrevCell = strRefCell
strSQL = "Select * From arms Where [dsn]='" & strRefCell & _
"'ORDER BY status"
With cmdGetMyData
Set .ActiveConnection = conADOConnection
.CommandText = strSQL
.CommandType = adCmdText
End With
Set rstMyData = cmdGetMyData.Execute()
If rstMyData.EOF Then
'MsgBox strRefCell & " BAD "
ActiveCell.Offset(0, 4).Value = "BAD"
boolPrevStatus = False
Else
'MsgBox strRefCell & " GOOD "
ActiveCell.Offset(0, 4).Value = "GOOD"
strPrevValue = rstMyData.Fields(4).Value
ActiveCell.Offset(0, 5).Value = strPrevValue
boolPrevStatus = True
End If
rstMyData.Close
End If
ActiveCell.Offset(1, 0).Activate
Next i
'Application.ScreenUpdating = True
conADOConnection.Close
End Su