Question on Runtime Error

magster06

Registered User.
Local time
Today, 12:51
Joined
Sep 22, 2012
Messages
235
Access 2010

With the help of pbaldy, my code is now validating for duplicate entries.

My problem is now with the rest of the code:

Code:
Private Sub RankOrder_BeforeUpdate(Cancel As Integer)
    Dim lngRankDup As Long
    lngRankDup = Nz(DLookup("[RankOrder]", "tblTestEvents", "[RankOrder]=" & RankOrder), 0)
    If lngRankDup <> 0 Then
        MsgBox "The Rank of " & [RankOrder] & " already exists in the database!" & vbCrLf & vbCrLf & "Please enter the number again!", vbInformation, "Rank Already Exists"
        Me.RankOrder = ""
        Me.RankOrder.SetFocus
    End If
End Sub

I get the error message: -2147352567 which states:
The macro of function set to the Beforeupdate property for this field is preventing MS Access from saving the data in the field

My question is this: is this an error that I can trap without any issues down the road?

Thanks!
 
In the before update event, rather than these 2 lines:

Me.RankOrder = ""
Me.RankOrder.SetFocus

you'd have

Cancel = True
Me.RankOrder.Undo
 
Boy, I have a lot to learn!

Thanks again for the much needed help!
 
Paul,

I was just curious, is the undo suppose to remove the data that was entered?

The reason I ask is because it will give focus to the data in the textbox, but does not remove it.

UPDATE!

Ok, I see what happens. I had already entered data into the textbox a couple of times and when Access reverted back (undo), it changed back to the data prior.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom