I'm using a form to add a new record to a table. the table has a autonumber as PK. I have a button that when clicked validate the entry from form fields to table fields. The problem is it would accept to add the new record the first time, I have to click a second time to make it go through. And this because the autonumber had to jump to a new number first.
Can please tell if there is a way to achieve that without having to click twice( just to let you know I'm using this code in the button Sub:
If Not Me.NewRecord Then
On Error GoTo ErrNew
Select Case Err
'Command not available
MsgBox "You cannot add a record at this time.", vbInformation, "Not Available"
MsgBox Err.Number & ":-" & vbCrLf & Err.Description
so the first click always dispalys "You cannot add a record at this time.", message.
Another thing as long the form is open I can perform the adding with no problem(only on click on the button) the problem happens only the first time I open the form
I don't know why you have it going to a new record twice. That could be your error. I use the following:
If DoubleCheck = -1 Then 'subroutine that checks for nulls
If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
If SaveInfo <> "" Then
If Me.DataEntry = 0 Then Me.DataEntry = -1
DoCmd.GoToRecord , , acNewRec