I am developing an access database with some forms that are only used for data entry. The problem is that, when I open any of these forms, access creates a new entry in the underlying table, including incrementing the autonumber primary key of the underlying table, and the autonumber remains incremented even if the user opts not to create the record in the database. This means that there are gaps in the sequence of autonumbers in the actual table due to all the times users open and close the form without committing changes.
I am using the following code in the beforeupdate method to allow users to discard bad data:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Provide the user with the option to save/undo
'changes made to the record in the form
If MsgBox("Data has been entered into this form." _
& vbCrLf & vbCrLf & "Do you want to save this data?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub
I had thought to use the beforeinsert event, but was having problems opening up the form when beforeinsert was used.
Can someone show me how to set things up so that these gaps do not get created in the sequence of autonumber values? This database will be used by perhaps 10 concurrent users.