I have a form on which data can added. Each records gets its own recordnumber which is made on moment of enetering data. (I cannot use the internal number because in backgrounf sometime records are added and deleted again)
If I look into the table I see that my field ID in this table starts numbering from 1 after some hundred records. I'm not sure but I think that somehow the recordcount give 0 on some unexpected moment.
Does anybodey see a mistake in the coding?
I use the code below to do so:
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Set con = CurrentProject.Connection
Set rst = New ADODB.Recordset
On Error GoTo Error_BeforeInsert
rst.Open "Ontvangsten", con, adOpenStatic, adLockPessimistic
If rst.RecordCount = 0 Then 'this is done for the situation the table is empty
Me!ID = 1
Else
rst.MoveLast
Forms![Ontvangsten]!Nummer = rst!ID + 1
End If
rst.Close
If I look into the table I see that my field ID in this table starts numbering from 1 after some hundred records. I'm not sure but I think that somehow the recordcount give 0 on some unexpected moment.
Does anybodey see a mistake in the coding?
I use the code below to do so:
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Set con = CurrentProject.Connection
Set rst = New ADODB.Recordset
On Error GoTo Error_BeforeInsert
rst.Open "Ontvangsten", con, adOpenStatic, adLockPessimistic
If rst.RecordCount = 0 Then 'this is done for the situation the table is empty
Me!ID = 1
Else
rst.MoveLast
Forms![Ontvangsten]!Nummer = rst!ID + 1
End If
rst.Close