If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Autonumber (Using Dmax) on Continuous Forms
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 the current record is saved. However, using a continuous form, it does not. When the form is first loaded it is incremented correctly, but once the current record is updated and saved, the new record lists the number 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 Function
__________________
jm |
#2
|
|||
|
|||
Autonumber (Using Dmax) on Continuous Forms
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.) -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Jeff Monroe" wrote in message ... 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 the current record is saved. However, using a continuous form, it does not. When the form is first loaded it is incremented correctly, but once the current record is updated and saved, the new record lists the number 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 Function -- Jeff Monroe |
Thread Tools | |
Display Modes | |
|
|