D
DEI
I am using the following ADO code to update records in a table, and it runs
very slowly. Does anyone have any suggestons about why? Is there a way to
make the updates run faster? The fields I am updating are not indexed -
thanks.
Public Sub Populate()
' - Populates blank fields.
' - ex. [LOC_CODE] and [MOD_CODE]
' - Fields targeted for update MUST have values in the first record.
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim fonename As String
Dim ftwoname As String
Dim fone As String
Dim ftwo As String
Set conn = CurrentProject.Connection
fonename = "LOC_CODE"
ftwoname = "MOD_CODE"
rs.Open "[ZIPS]", conn, adOpenKeyset, adLockOptimistic
'Update LOC_CODE
'Check to see if first record is null
rs.MoveFirst
If IsNull(rs.Fields(fonename)) Then
MsgBox ("First Record CANNOT be Null")
Exit Sub
End If
For x = 1 To rs.RecordCount
If IsNull(rs.Fields(fonename)) Then
rs(fonename) = fone
rs.Update
End If
fone = rs.Fields(fonename)
rs.MoveNext
Next x
'Update MOD_CODE
'Check to see if first record is null
rs.MoveFirst
If IsNull(rs.Fields(ftwoname)) Then
MsgBox ("First Record CANNOT be Null")
Exit Sub
End If
For x = 1 To rs.RecordCount
If IsNull(rs.Fields(ftwoname)) Then
rs(ftwoname) = fone
rs.Update
End If
fone = rs.Fields(ftwoname)
rs.MoveNext
Next x
rs.Close
Set rs = Nothing
Set conn = Nothing
End Sub
very slowly. Does anyone have any suggestons about why? Is there a way to
make the updates run faster? The fields I am updating are not indexed -
thanks.
Public Sub Populate()
' - Populates blank fields.
' - ex. [LOC_CODE] and [MOD_CODE]
' - Fields targeted for update MUST have values in the first record.
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim fonename As String
Dim ftwoname As String
Dim fone As String
Dim ftwo As String
Set conn = CurrentProject.Connection
fonename = "LOC_CODE"
ftwoname = "MOD_CODE"
rs.Open "[ZIPS]", conn, adOpenKeyset, adLockOptimistic
'Update LOC_CODE
'Check to see if first record is null
rs.MoveFirst
If IsNull(rs.Fields(fonename)) Then
MsgBox ("First Record CANNOT be Null")
Exit Sub
End If
For x = 1 To rs.RecordCount
If IsNull(rs.Fields(fonename)) Then
rs(fonename) = fone
rs.Update
End If
fone = rs.Fields(fonename)
rs.MoveNext
Next x
'Update MOD_CODE
'Check to see if first record is null
rs.MoveFirst
If IsNull(rs.Fields(ftwoname)) Then
MsgBox ("First Record CANNOT be Null")
Exit Sub
End If
For x = 1 To rs.RecordCount
If IsNull(rs.Fields(ftwoname)) Then
rs(ftwoname) = fone
rs.Update
End If
fone = rs.Fields(ftwoname)
rs.MoveNext
Next x
rs.Close
Set rs = Nothing
Set conn = Nothing
End Sub