Incrementing Field

  • Thread starter Thread starter Danny Jacobs
  • Start date Start date
D

Danny Jacobs

Can anybody tell me how I can create a form control that automatically
defaults to the value of the previous record +1.

e.g. field1 field2
1 100
2 151
3 66
7 500 (Over-written example)
8

I want field1 to default to the previous value +1. If I over-write the value
then the rule will hold for the next entry.

--

Danny Jacobs, Tracey, Holly and Asha Strom
Tel: +644 477 4302
Fax: +644 477 4333
Mobile: 0274 418 417 (DJ), 025 669 0001 (TS)
 
Private Sub Form BeforeUpdate(Cancel As Integer)
If IsNull(Me.Field) Then
Me.Field = DMax("[Field]", "Table") + 1
End If
End Sub
 
Danny Jacobs said:
Can anybody tell me how I can create a form control that automatically
defaults to the value of the previous record +1.

e.g. field1 field2
1 100
2 151
3 66
7 500 (Over-written example)
8

I want field1 to default to the previous value +1. If I over-write the value
then the rule will hold for the next entry.

--

Danny Jacobs, Tracey, Holly and Asha Strom
Tel: +644 477 4302
Fax: +644 477 4333
Mobile: 0274 418 417 (DJ), 025 669 0001 (TS)

In the BeforeUpdate event of the form...

If IsNull(Me!Field1) = True Then
Me!Field1 = Nz(DMax("Field1", "YourTable"), 0) + 1
End If

Make sure that Field1 doesn't have a default value in the table or form.
 
Back
Top