Forcing Access to think the Esc key was pressed?

mrb783

Registered User.
Local time
Today, 12:09
Joined
Oct 28, 2008
Messages
40
I have the following function:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

    If (IsNull(Me.CaseID) = True) Then
        Msgbox "This Subcase record is not tied to a valid Master Case record. Please cancel your changes by hitting Escape.", vbOKOnly, "ERROR"
        Cancel = True
        Exit Sub
    End If

End Sub
What this does is test to see whether or not CaseID contains a value. If it does not, this means that the parent table has no record in it and someone is attempting to add a record into this table without a parent record to tie it to...which is bad.

Now, the code above works to cancel any changes that were made before they create a record in the database. However, as you can see from my Msgbox statement, it does not clear the information from the form and I am forced to then ask them to hit the Esc button to actually clear the form contents.

I want to change this to an OkayCancel Msgbox that performs the same function as hitting the Esc key to truly cancel the changes and reset the form contents...I'm not sure if this is possible, but thanks in advance for any replies!
 
Try the following code modification:
Code:
[COLOR="Navy"]Private Sub[/COLOR] Form_BeforeUpdate(Cancel [COLOR="navy"]As Integer[/COLOR])

    [COLOR="navy"]If[/COLOR] (IsNull(Me.MyField) = [COLOR="navy"]True[/COLOR]) [COLOR="navy"]Then[/COLOR]
        MsgBox "This Subcase record is not tied to a valid Master Case record.", vbOKOnly, "ERROR"
        [b][i]Me.Undo[/i][/b]
        Cancel = [COLOR="navy"]True
        Exit Sub
    End If

End Sub[/COLOR]
 
Fantastic, that worked like a charm. Thank you so much.
 

Users who are viewing this thread

Back
Top Bottom