Re: BeforeUpdate event



Sher wrote:
I have created a before update event listed below. What I would also
like it to do is go to the record that is in the database. I thought
that was what I was doing but it isn't working. Can someone please
help.

Private Sub SSN_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("[SSN]", "Security", "[SSN]= '" & Me![SSN] &
"'")) Then MsgBox "This SSN already exists."
Cancel = True
Me.Undo
DoCmd.GoToRecord , , acFirst
DoCmd.FindRecord SSN

End If

End Sub

You cannot navigate in the middle of an update event. Your code needs to cancel
the update, issue an Undo on the form, and then it might work to move to another
record. I'm not sure even that would work without testing it though.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


.



Relevant Pages

  • RE: inputmask
    ... aan = Hour ... Update event. ... If not cancel ... Private Sub Aankomen_BeforeUpdate ...
    (microsoft.public.access.formscoding)
  • RE: GoToControl problems
    ... The after update event code occurs after the value is ... Private Sub txtDate_rcp_BeforeUpdate ... setting the focus while in a control to itself, but I am not absolutely sure. ... you can use the Cancel capability of that event to cancel the update of the ...
    (microsoft.public.access.formscoding)
  • Re: How to change bound continuous form with required fields
    ... that users want to get some of the data from outside the database. ... One option may be to use the Before Update event for notification only. ... That is, don't cancel, and don't undo. ... No need to wait for the Unload event. ...
    (microsoft.public.access.forms)
  • Re: clear and delete
    ... Then MsgBox "The name you entered is already listed in the database. ... And in that event you can cancel the update by cancelling the ... Private Sub Form_BeforeUpdate ... UserID field is an autonumber, you can't keep a discarded entry from ...
    (microsoft.public.access.formscoding)
  • Re: Limit entries to a form
    ... Cancel the BeforeInsert event procedure of the form if the maximum number of ... Private Sub Form_BeforeInsert ... cancel the event. ... > server for the database. ...
    (microsoft.public.access.forms)