record numbers in step order

G

Guest

I have the following code in a form attached to event of a field called
Anything

Private Sub Anything_BeforeUpdate(Cancel As Integer)
Me![SID] = (Nz(DMax("[Sid]", "Steps", "[pID]=" & [PID]), 0) + 1)
End Sub

I have put it in to get sequential numbering and it works partly
Problems are that if I go into the form field Antything again for that
record and add or delete or make any changes it will increment the number
again. I dont want it to do this, once the number is generated it should be
fixed for that record. What do I need , some sort of If statement?

At some stage also I may need to insert or delete a record in which case
this no will be out of sync - but I will leave that to another post?
 
D

Douglas J Steele

Private Sub Anything_BeforeUpdate(Cancel As Integer)

If IsNull(Me![SID]) Then
Me![SID] = (Nz(DMax("[Sid]", "Steps", "[pID]=" & [PID]), 0) + 1)
End If

End Sub
 
G

Guest

thanks this works fine

Douglas J Steele said:
Private Sub Anything_BeforeUpdate(Cancel As Integer)

If IsNull(Me![SID]) Then
Me![SID] = (Nz(DMax("[Sid]", "Steps", "[pID]=" & [PID]), 0) + 1)
End If

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


martyn said:
I have the following code in a form attached to event of a field called
Anything

Private Sub Anything_BeforeUpdate(Cancel As Integer)
Me![SID] = (Nz(DMax("[Sid]", "Steps", "[pID]=" & [PID]), 0) + 1)
End Sub

I have put it in to get sequential numbering and it works partly
Problems are that if I go into the form field Antything again for that
record and add or delete or make any changes it will increment the number
again. I dont want it to do this, once the number is generated it should be
fixed for that record. What do I need , some sort of If statement?

At some stage also I may need to insert or delete a record in which case
this no will be out of sync - but I will leave that to another post?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top