Delete Command Button Issue

S

scott04

Hello
I am having a small issue with my delete command button. I have several
valadation rules currently in my database. I also have a delete command
button. The form has about 60 fields with lets say 15 required. If a user
enters in 3 fields and then realizes they want to delete the record the
delete button since the other valadation rules are seeing fields have not
been filled out. Is there another command button i can put on the form to go
along with delete? My button works fine on existing records. Any
suggustions? Below is the code on the click:
Private Sub DeleteRecord_Click()
Dim intResponse As String
intResponse = MsgBox("Do you wish to delete this record?", vbYesNo, "Delete
Record")
If intResponse = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True

Else
Cancel = True

End If
End Sub
 
A

Allen Browne

Try this:
If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

That should work, unless the control the user is actually in is bound to a
required field. In that case, Access won't let the focus out of that
control, so it can't get to the command button to run your code. Teach users
to press the Esc key to undo the record when this occurs.
 
S

scott04

Allen,
Thanks for your feedback as it much appreciated. I probably will just teach
the user to use the esc key if they make this mistake. Thank you for your
quick reply!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top