Cancel from OnError Event

G

Guest

I have created the following code for the error of duplicate data. I have a
form and a subform. When I type duplicate info on the form I want it not
only to tell me that the data is duplicate but to go to the original record.
I don't know the syntax to cancel the BeforeUpdate event from the OnError
event.


Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3022 Then
Response = acDataErrContinue
msgbox "You have entered duplicate data"
strDrawNo = Combo_DrawNo.Value

'NEED SOMETHING HERE TO CANCEL THE UPDATE OF THE FORM

Combo_DrawNo.SetFocus
DoCmd.FindRecord strDrawNo, acAnywhere
frmAssyDrawNo.SetFocus
End If

End Sub
 
S

strive4peace

use the form BeforeUpdate event

Cancel = True
me.undo

~~~

to find the original record:

'find the first value that matches

'------------------- choose one of these
'if DrawNo is a string
Me.RecordsetClone.FindFirst "DrawNo = '" & Combo_DrawNo & "'"

'if DrawNo is a number
Me.RecordsetClone.FindFirst "DrawNo = " & Combo_DrawNo
'---------------

'if a matching record was found, then move to it
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

Let me re-phrase. I don't know how to coordinate between the OnError event
and the BeforeUpdate. At 1st I tried to put all the code in the BeforeUpdate
event with

On Error Goto ErrHandler
..
..
..
ErrHandler:
if err.number=3022
..
..
..





That did not work so I used the form's OnError event which does cature the
error.

I need to cancel the update from WITHIN the OnError event.
 
G

Guest

Nevermind... the me.undo works from with the OnError Event

Now this works :)

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3022 Then
Response = acDataErrContinue
msgbox "You have entered duplicate data"
strDrawNo = Combo_DrawNo.Value
me.undo
Combo_DrawNo.SetFocus
DoCmd.FindRecord strDrawNo, acAnywhere
frmAssyDrawNo.SetFocus
End If

End Sub
 
S

strive4peace

glad you got it ;)

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top