J
Jürgen Germonpré
Dear all,
I have this Access table (up to 300.000 records). For each record I have to
generate an calculated number and update a field with it. So every single
record has to be updated with a unique number.
I wrote this procedure in VBA, which cycles al records in a recordset,
calculates and updates the record....
But this takes up a lot of time !!!
I can image there is a much better way to do this and I wondered if anybody
could help me ???
Hereby my original-super-slow code.
Public Sub Numbering()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim lMaxRec As Long
Dim bFirstRun As Boolean
Set db = CurrentDb()
Set rs = db.OpenRecordset(sTableName)
lMaxRec = rs.RecordCount
If lMaxRec > 0 Then
rs.MoveFirst
bFirstRun = True
While Not rs.EOF
rs.Edit
rs("MyNumberField") = GetMyNumber
rs.Update
rs.MoveNext
Wend
Else
MsgBox "No records in table: " & sTableName, vbCritical
End If
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
Thanks for your help.
JG
I have this Access table (up to 300.000 records). For each record I have to
generate an calculated number and update a field with it. So every single
record has to be updated with a unique number.
I wrote this procedure in VBA, which cycles al records in a recordset,
calculates and updates the record....
But this takes up a lot of time !!!
I can image there is a much better way to do this and I wondered if anybody
could help me ???
Hereby my original-super-slow code.
Public Sub Numbering()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim lMaxRec As Long
Dim bFirstRun As Boolean
Set db = CurrentDb()
Set rs = db.OpenRecordset(sTableName)
lMaxRec = rs.RecordCount
If lMaxRec > 0 Then
rs.MoveFirst
bFirstRun = True
While Not rs.EOF
rs.Edit
rs("MyNumberField") = GetMyNumber
rs.Update
rs.MoveNext
Wend
Else
MsgBox "No records in table: " & sTableName, vbCritical
End If
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
Thanks for your help.
JG