Can't Go To New record

I'm calling a public function from command button which goes to a new record on a single form:

Public Function NewRecord(ctl As Control)
       DoCmd.GoToRecord , , acNewRec
End Function

Problem is if a record is being edited (dirty) and I click the Add Record button before the record gets saved, Access tells me I can't go to the specified record (run-time error 2105). Not sure why this is so. I have an event procedure in the BeforeUpdate of the form which confirms data changes:

Private Sub Form_BeforeUpdate(Cancel As Integer)

    If Me.Dirty Then

    Dim msg, style, TITLE, Response
    msg = "Record(s) have been added or changed." & vbCrLf & "Do you want to save the changes?"
    style = vbYesNo + vbQuestion
    TITLE = "Data Change Confirmation"
        Response = MsgBox(msg, style, TITLE)
            If Response = vbYes Then
            End If
End If
End Sub

The BeforeUpdate triggers when I click the New Record Button but after that the run-time error 2105 pops up highlighting 'DoCmd.GoToRecord , , acNewRec'.

Why am I unable to got to a new record in this situation?? The Form's Allow Additions property is set to Yes.



Question Info

Last updated December 4, 2018 Views 3,561 Applies to:

Just exactly like this:



just the word FORM, not the form name at all, just the word Form in brackets.

Microsoft Access MVP 2008, 2009, 2011
If a post was helpful click the FOUND THIS HELPFUL link

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.