From: Kurt Heisler on
I put code in the Before Update event of my form to verify that two
fields are complete (i.e., Not Null) before saving. The code is:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.FirstName) Then
MsgBox "Please enter a first name."
Cancel = True
Me.FirstName.SetFocus
ElseIf IsNull(Me.LastName) Then
MsgBox "Please enter a last name."
Cancel = True
Me.LastName.SetFocus
End If

End Sub

Also on my form is a Delete button that deletes the record. The
problem is that if the user starts a new record, and then clicks the
delete button without having completed one of the two fields, the
Before Update event is triggered and he's asked to, "Please enter
a ... name." Any way to override this?
From: Allen Browne on
Undo the record before deleting it.

If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"Kurt Heisler" <heislerkurt(a)gmail.com> wrote in message
news:1cf62daf-9b0a-4cc2-b67d-a4e6b11e3118(a)t34g2000prd.googlegroups.com...
> I put code in the Before Update event of my form to verify that two
> fields are complete (i.e., Not Null) before saving. The code is:
>
> Private Sub Form_BeforeUpdate(Cancel As Integer)
>
> If IsNull(Me.FirstName) Then
> MsgBox "Please enter a first name."
> Cancel = True
> Me.FirstName.SetFocus
> ElseIf IsNull(Me.LastName) Then
> MsgBox "Please enter a last name."
> Cancel = True
> Me.LastName.SetFocus
> End If
>
> End Sub
>
> Also on my form is a Delete button that deletes the record. The
> problem is that if the user starts a new record, and then clicks the
> delete button without having completed one of the two fields, the
> Before Update event is triggered and he's asked to, "Please enter
> a ... name." Any way to override this?

From: Jeanette Cunningham on
Change your delete code to check for a dirty record and a new record before
deleting the record.

If Me.Dirty = True Then
Me.Undo
End If

If Not Me.NewRecord Then
'the code to delete goes here
End If


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


"Kurt Heisler" <heislerkurt(a)gmail.com> wrote in message
news:1cf62daf-9b0a-4cc2-b67d-a4e6b11e3118(a)t34g2000prd.googlegroups.com...
>I put code in the Before Update event of my form to verify that two
> fields are complete (i.e., Not Null) before saving. The code is:
>
> Private Sub Form_BeforeUpdate(Cancel As Integer)
>
> If IsNull(Me.FirstName) Then
> MsgBox "Please enter a first name."
> Cancel = True
> Me.FirstName.SetFocus
> ElseIf IsNull(Me.LastName) Then
> MsgBox "Please enter a last name."
> Cancel = True
> Me.LastName.SetFocus
> End If
>
> End Sub
>
> Also on my form is a Delete button that deletes the record. The
> problem is that if the user starts a new record, and then clicks the
> delete button without having completed one of the two fields, the
> Before Update event is triggered and he's asked to, "Please enter
> a ... name." Any way to override this?