Automatic calculations!!!

Joined
Jul 22, 2005
Messages
9
Reaction score
0
Hello everyone,

I have a form where a user can add/append new records to the db table which alreay has records in it. However I am facing the following problem. I have listed the steps that I followed. Please take a look and help me solve this..

1. I am able to automatically calculate (max value for that field + 1) for my field(NCR_NCR_NUMBER) and save it in my table with a save command button.

The code that I have used is :
-----------------------------------------------------------------------------------------------------------------
Private Sub New_NCR_NUMBER_Click()
'On click of button a new NCR_NUMBER is generated and
'focus is moved to NCR_AIMII_MODIFIER.
Me![NCR_NCR_NUMBER] = NewNCR_NUMBER()
Me![NCR_AIMII_MODIFIER].SetFocus 'NCR_AIMMI_MODIFIER is my next
'field in the form
Me![New_NCR_NUMBER].Enabled = False
End Sub
-----------------------------------------------------------------------------------------------------------------
Public Function NewNCR_NUMBER() As Long

On Error GoTo NextID_Err

Dim lngNextID As Long

'Find highest NCR_NCR_NUMBER in the NCR_DIM table and add 1

lngNextID = DMax("[NCR_NCR_NUMBER]", "NCR_DIM") + 1

'Assign function the value of the Next ID
NewNCR_NUMBER = lngNextID

'Exit function now after successful incrementing or after error message
Exit_NewNCR_NUMBER:
Exit Function
---------------------------------------------------------------------------------------------------------------



2. Now I have an other command button to duplicate the record entered.
And the code that I have for this button is:
---------------------------------------------------------------------------------------------------------------
Private Sub Duplicate_Record_Click()
On Error GoTo Err_Duplicate_Record_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70

DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Exit_Duplicate_Record_Click:
Exit Sub

Err_Duplicate_Record_Click:
MsgBox Err.Description
Resume Exit_Duplicate_Record_Click

End Sub
-------------------------------------------------------------------------------------------------------------------------


3. However, when I click the duplicate_record command button, I am not able to generate a duplicate record with a different ((max of NCR_NCR_NUMBER) +1). It is creating a duplicate record set with the same NCR_NCR_NUMBER in an error table. How can I solve the problem and save a duplicate record with the automatically generated field.

Hope I am clear..

Please help!!!!!!!!

Thanks ,
 
Back
Top