Autonumber (Using Dmax) on Continuous Forms

J

Jeff Monroe

I have created a continuous that I want to increment a number (by 1
each time a record is saved. I have found when using the code below
the field increments to the next number in the new record once th
current record is saved. However, using a continuous form, it does not
When the form is first loaded it is incremented correctly, but once th
current record is updated and saved, the new record lists the numbe
that was lised on load

Can this work with continuous forms?

Thanks.


Private Sub Form_Error(DataErr As Integer, Response As Integer)
On Error GoTo Err_Form_Error

Response = IncrementField(DataErr)

Exit_Form_Error:
Exit Sub

Err_Form_Error:
MsgBox Err.Description
Resume Exit_Form_Error

End Sub

Function IncrementField(DataErr)
If DataErr = 3022 Then
Me!FA_no = DMax("FA_no", "tblFA_Log") + 1
IncrementField = acDataErrContinue
End If
End Functio
 
A

Allen Browne

Jeff, instead of waiting for an error, use the BeforeUpdate event of the
form to assign the next available:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.FA_no) Then
Me.FA_no = DMax(...
End If
End Sub

It strikes me as better to assign the number than to wait for an error to
occur.

Form_BeforeUpdate is the last possible moment before the record is saved, so
using this event reduces the chance that 2 people entering records at the
same time will be assigned the same number (as they could be if you used
Form_BeforeInsert.)
 

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

Similar Threads


Top