run-time error 2108 you must save the field before...

I got this error message when I enter a new record with same PO Number: Run-time error 2108: you must save the field before you execute the GoToControl action, the GoTOControl method, or the SetFocus method.

It highlights the line: Me.Bookmark rsc.Bookmark

Private Sub PONumber_BeforeUpdate(Cancel As Integer)
    Dim PONumber As String
    Dim stLinkCriteria As String
    Dim rsc As DAO.Recordset
    Set rsc = Me.Recordset.Clone

    PONumber = Me.PONumber
    stLinkCriteria = "[PONumber]=" & PONumber
    
    'Check tblMaster for duplicate PONumber
    If DCount("PONumber", "PO", stLinkCriteria) > 0 Then
        'Message box warning of duplication
        MsgBox "PO already in database." _
             & vbCr & vbCr & "You will now be taken to the record.", _
               vbInformation, "Duplicate Information"
        'Undo duplicate entry
        Me.Undo
        'Go to record of original PO Number
        rsc.FindFirst stLinkCriteria
         If rsc.NoMatch Then
         Else
            Me.Bookmark = rsc.Bookmark
         End If
    End If

    Set rsc = Nothing
End Sub
 

Question Info


Last updated July 6, 2018 Views 2,679 Applies to:
Answer

Then put a line

Me.Undo

before the line moving to another record.

 

John W. Vinson/MVP

1 person was helped by this reply

·

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.