An update query selects all the records that meet the criteria and changes the field(s) at one time. There is no looping, The value is calculated once - all records get the same number.
It appears that "Artikelnr" is a text field?
I threw together some code.... not sure that it will work because I am not sure what the field types are.
I am not sure how you were executing the query, but try this on a copy of the dB:
Code:
Option Compare Database '<-should be at the top of every module
Option Explicit '<-should be at the top of every module
Public Sub UpdateArtikelnr()
Dim d As DAO.Database
Dim r As DAO.Recordset
Dim MaxNum As Long
Dim sSQL As String
Dim RC As Long
Set d = CurrentDb
'intialize max number
MaxNum = 0
'get max Artikelnr number - convert from text to Long
sSQL = "SELECT Max(CLng(artikelen_nieuw.Artikelnr)) AS MaxArtikelnr"
sSQL = sSQL & " FROM artikelen_nieuw"
Set r = d.OpenRecordset(sSQL)
If Not r.BOF And Not r.EOF Then
MaxNum = r.Fields(0)
End If
r.Close
'get the records to update
sSQL = "SELECT artikelen_nieuw.Artikelnr, artikelen_nieuw.Actie"
sSQL = sSQL & " FROM artikelen_nieuw"
sSQL = sSQL & " WHERE (((artikelen_nieuw.Artikelnr) ='TOEVOEGEN') AND ((artikelen_nieuw.Actie) = 'TOEVOEGEN'));"
' Debug.Print sSQL
Set r = d.OpenRecordset(sSQL)
If r.BOF And r.EOF Then
MsgBox "No records found"
Else
r.MoveLast
'get number of records
RC = r.RecordCount
r.MoveFirst
MsgBox "Updating " & RC & " records" & vbNewLine & vbNewLine & "Current Max number is " & MaxNum
Do Until r.EOF
MaxNum = MaxNum + 1
r.Edit
r("Artikelnr") = CStr(MaxNum)
r("Actie") = "TOEGEVOEGD"
r.Update
r.MoveNext
Loop
End If
On Error Resume Next
'done - now clean up
r.Close
Set r = Nothing
Set d = Nothing
MsgBox "Done"
End Sub