Cancelling update for current record

C

CathyZ

Hi,

I am creating a database for a school, there is one main form with eight
other forms linked to it, so I am using linked forms instead of subforms.
When the user clicks on one of the command buttons to open a linked form, the
form opens up with a new record and the student ID and name is inserted on
the form, this creates a new record, but if the user changes their mind and
decides not to enter any other data for the student, I don't want the record
to be saved.

I tried this code below. It works but gives an error message to the user,
in a dialog box which they have to close. Is there anyway of cancelling
update and closing the form, without the error message?

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me![formTerm]) Or IsNull(Me![schoolYear]) Then
Cancel = True
End If
End Sub

I tried using the cancelupdate method, but have problems setting the current
record to cancel.

Any help appreciated.
 
Top