Double Escape Key VB equivalent

CadMonkey

Misplaced But Useful
Local time
Today, 15:38
Joined
May 19, 2004
Messages
47
People of this most excellent form,

I have been racking my brains and seraching high and low to try and figure this one....

All I'm trying to do is cancel the creation of a new record on a form when it is detected that a text box has a null value. The bit I'm stuck on is getting the record to dissapear. I've tried the:

me.undo - It doesn't work!

Pressing the escape key twice has the desired affect. Does anyone knopw the VBA code equivalent of this action?? You're a star if you do!

Here's my code: :confused:

Private Sub Form_BeforeInsert(Cancel As Integer)

If IsNull(Forms![frmSchedule]![Schedule_ID]) = True Then
MsgBox "Have recognised that schedule is empty"
'need code here to cancel new record
Exit Sub
Else
End If
...


Many thanks,

Simon
 
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.MyTextBox) Then Cancel = True 
End Sub
 
Mile-O-Phile said:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.MyTextBox) Then Cancel = True 
End Sub

That code did the trick, perfectly. I just had to make sure I add an exit sub there after the if statment.

Many thanks Mile-o-Phile!
 
CadMonkey said:
I just had to make sure I add an exit sub there after the if statment

Why would you need an Exit Sub statement? There's an End Sub straight after the IF statement
 

Users who are viewing this thread

Back
Top Bottom