auto number problem on primary key

rashidzaib

Registered User.
Local time
Today, 01:47
Joined
Aug 12, 2007
Messages
32
hy
i hope all r fine.
sorry for disturbing you again.
i have problem in auto generation of primary key field.
on field i have written on enter event the dmax function.
but when cursor is going on that field automaticaly next number is appered
and also it update the old record if i first time run the form. and also if u r deleting the rcord it will show u next max number example
if u have 4 record and next max number is 5 then if u delete the previoud item code will be six and so on.

i also have enter the code on before update form
Private Sub form_BeforeUpdate(Cancel As Integer)
If Not (Me.NewRecord) Then
If MsgBox("would u save changes to this record", vbQuestion + vbYesNo + vbDefaultButton1, "save changes to record") = vbNo Then
Me.Undo
End If

else
If MsgBox("would u save this record", vbQuestion + vbYesNo + vbDefaultButton1, "save this to record") = vbNo Then
Me.Undo
end if
End If
End Sub
but when i am clicking any button on form it is showing that do u want save changes
or
even deleting record it is showing that msg.
is there any solution so that i should get rid of this problem.
thank u and best regard
take care bye
 
Auto-Number

Try using the onload event of the form . This will lookup the last entry on the table and add one more record. After this to go to the next Record when the form is open You can create a command Button and on the click event add the same DMax code as in the onload event.
One thing you have to understand the DMax wont work if the field's data type is set to auto-number. Make sure the field has a Number data type.
 
this is nearly working

hy coyote
thank u very much for giving me reply
this working on load event and next record button. every thing is ok
but little modification is needed. if i load a form next number is generated. and if for example i dont want to create new record then this number is also saved in table. for this i used after update event on the form and write this code
Private Sub form_BeforeUpdate(Cancel As Integer)
If Not (Me.NewRecord) Then
If MsgBox("would u save changes to this record", vbQuestion + vbYesNo + vbDefaultButton1, "save changes to record") = vbNo Then
Me.Undo
End If

else
If MsgBox("would u save this record", vbQuestion + vbYesNo + vbDefaultButton1, "save this to record") = vbNo Then
Me.Undo
end if
End If
End Sub
this is working if i dont want to create the record.
now the problem is this if i want to go to next button and the msg is appear u want to save the record.
i want if i click the save button and then click the next record button this msg should not appear.
any help should realy be appriciated.
thank u and best regard
ur truly rashid zaib
 

Users who are viewing this thread

Back
Top Bottom