Im using this code to create a common link between records in a table. The problem i have is that the table contains 87000 records an this update will take approx 4 hours to run.
does anyone have any ideas how to speed this code up
'========================================
Function CreateLink()
'---------------------------------------
Dim ThisDB As DAO.Database
Dim MySet As DAO.Recordset
Dim strSQL As String
Dim MyVal1 As Variant
Dim e As Integer
Dim c As Long
Dim d As Long
e = 0
DoCmd.SetWarnings False
If IsNull(DMax("[Index]", "table1")) Then
c = 1
Else
c = DMax("[Index]", "table1") + 1
End If
d = DCount("[FIELD1]", "table1", "[Index] is null")
Do While e < d
strSQL = "SELECT * FROM Top1 WHERE index is null"
Set ThisDB = CurrentDb()
Set MySet = ThisDB.OpenRecordset(strSQL, dbOpenDynaset)
MyVal1 = MySet!FIELD1
If MyVal1 = "TRANS" Then
c = c + 1
Else
End If
DoCmd.RunSQL "UPDATE Top1 SET Top1.[Index] = " & c & " ;"
e = e + 1
NLeft = DCount("[FIELD1]", "table1", "[Index] is null")
Loop
DoCmd.SetWarnings True
End Function
'-------------------------------------------
"My God! It's full of stars...
does anyone have any ideas how to speed this code up
'========================================
Function CreateLink()
'---------------------------------------
Dim ThisDB As DAO.Database
Dim MySet As DAO.Recordset
Dim strSQL As String
Dim MyVal1 As Variant
Dim e As Integer
Dim c As Long
Dim d As Long
e = 0
DoCmd.SetWarnings False
If IsNull(DMax("[Index]", "table1")) Then
c = 1
Else
c = DMax("[Index]", "table1") + 1
End If
d = DCount("[FIELD1]", "table1", "[Index] is null")
Do While e < d
strSQL = "SELECT * FROM Top1 WHERE index is null"
Set ThisDB = CurrentDb()
Set MySet = ThisDB.OpenRecordset(strSQL, dbOpenDynaset)
MyVal1 = MySet!FIELD1
If MyVal1 = "TRANS" Then
c = c + 1
Else
End If
DoCmd.RunSQL "UPDATE Top1 SET Top1.[Index] = " & c & " ;"
e = e + 1
NLeft = DCount("[FIELD1]", "table1", "[Index] is null")
Loop
DoCmd.SetWarnings True
End Function
'-------------------------------------------
"My God! It's full of stars...