PC Review


Reply
Thread Tools Rate Thread

Delete code competing with BeforeUpdate validation

 
 
Kurt Heisler
Guest
Posts: n/a
 
      3rd Jun 2010
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?
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      3rd Jun 2010
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" <(E-Mail Removed)> wrote in message
news:1cf62daf-9b0a-4cc2-b67d-(E-Mail Removed)...
> 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?


 
Reply With Quote
 
Jeanette Cunningham
Guest
Posts: n/a
 
      3rd Jun 2010
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" <(E-Mail Removed)> wrote in message
news:1cf62daf-9b0a-4cc2-b67d-(E-Mail Removed)...
>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?



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent BeforeUpdate code on Delete - Me.Undo not working HeislerKurt@gmail.com Microsoft Access Form Coding 2 2nd Jul 2007 01:31 PM
Validation and Dirty in BeforeUpdate of Form lad5ko via AccessMonster.com Microsoft Access Getting Started 6 22nd May 2006 07:24 PM
BeforeUpdate Validation problem =?Utf-8?B?Q2FybG9zIENhcmFjY2lvbGk=?= Microsoft Access 1 16th Jan 2004 01:32 PM
Help using Validation and beforeUpdate? a better way? Carlos Silva Microsoft Access Form Coding 1 16th Jul 2003 05:57 AM
Data Validation Useing BeforeUpdate Herschel Elkins Microsoft Access Form Coding 1 3rd Jul 2003 04:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 PM.