Error occurs when pressing new record button

  • Thread starter Thread starter Amir
  • Start date Start date
A

Amir

Hi!
When I press the "new record" button I've made,
I get Error number 2499, which says that I can't
use the GoToRecord action on an object in design mode.

Error occurs on line "DoCmd.GoToRecord , , acNewRec"

If I use Access' navigation buttons, error does not occur.

What can I do?

Here is the button's code:

Private Sub btnAddNewReceiptEvent_Click()
On Error GoTo Err_btnAddNewReceiptEvent_Click
DoCmd.GoToRecord , , acNewRec
If Not IsNull(Me.OpenArgs) Then
Me!ReceiptNumber.SetFocus
Me!ReceiptNumber.Text = Me.OpenArgs
Me!txtProjectName.SetFocus
Me.Requery
End If

Exit_btnAddNewReceiptEvent_Click:
Exit Sub

Err_btnAddNewReceiptEvent_Click:
'MsgBox Err.Description
MsgBox Err.Number & Err.Description, , "error"
Resume Exit_btnAddNewReceiptEvent_Click

End Sub

Regards,
Amir.
 
Hi Amir

There could be several reasons why the form cannot go to the new record,
e.g.:
- It is already at the new record.
- The current record is dirty and cannot be saved (e.g. required field
missing).
- The form's AllowAdditions property is set to No.
- The form's RecordSource is a query that does not accept new records.

Try something like this:

Private Sub btnAddNewReceiptEvent_Click()
On Error GoTo Err_btnAddNewReceiptEvent_Click

If Me.Dirty Then 'Save first.
Me.Dirty = False
End If

If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If

If Len(Nz(Me.OpenArgs, vbNullString)) > 0 Then
Me!ReceiptNumber = Me.OpenArgs
Me!txtProjectName.SetFocus
Me.Dirty = False
End If

Exit_btnAddNewReceiptEvent_Click:
Exit Sub

Err_btnAddNewReceiptEvent_Click:
'MsgBox Err.Description
MsgBox Err.Number & Err.Description, , "error"
Resume Exit_btnAddNewReceiptEvent_Click
End Sub
 
OK, I think i'll just print a message saying all the possibilities.
Thank you very much, Allen!
 
Back
Top