delete record with blank required field

L

laavista

I have a form with 12 fields bound to a table--the 3rd field is a required
field set at table level, and have a "delete" button on form.

Scenario: user fills in the 1st or 2nd field and leaves the 3rd, required,
field blank.
User clicks on "delete" button.

I use the following code when "delete" button is clicked:
===========================
If Me.Dirty = True Then Me.Dirty = False

If Me.NewRecord = -1 Then
MsgBox "New record--nothing to delete.", vbInformation, "No delete"
Exit Sub
End If

DeleteTheRecord 'call module & delete if they say yes
=====================================
If I don't "save" the record first using "If Me.Dirty = True Then Me.Dirty =
False", then newrecord is set to -1 and doesn't delete the record.

If I "save" the record using "If Me.Dirty = True Then Me.Dirty = False",
then it goes into my error handling routine because a required field is blank.

Any suggestions would be greatly appreciated.

(I'm using Access 2007)
 
M

Marshall Barton

laavista said:
I have a form with 12 fields bound to a table--the 3rd field is a required
field set at table level, and have a "delete" button on form.

Scenario: user fills in the 1st or 2nd field and leaves the 3rd, required,
field blank.
User clicks on "delete" button.

I use the following code when "delete" button is clicked:
===========================
If Me.Dirty = True Then Me.Dirty = False

If Me.NewRecord = -1 Then
MsgBox "New record--nothing to delete.", vbInformation, "No delete"
Exit Sub
End If

DeleteTheRecord 'call module & delete if they say yes
=====================================
If I don't "save" the record first using "If Me.Dirty = True Then Me.Dirty =
False", then newrecord is set to -1 and doesn't delete the record.

If I "save" the record using "If Me.Dirty = True Then Me.Dirty = False",
then it goes into my error handling routine because a required field is blank.


I might think about disabling the delete button when a
record becomes dirty and teaching your users to use the Esc
key to undo the changes.

I guess what you do depends on how you want to deal with
existing records that are being edited or if a new record is
in progress. Maybe you should try using Me.Undo instead of
deleting a record that is being edited (existing or new) and
only delete records that are not dirty or ???
 
J

John W. Vinson

I have a form with 12 fields bound to a table--the 3rd field is a required
field set at table level, and have a "delete" button on form.

Scenario: user fills in the 1st or 2nd field and leaves the 3rd, required,
field blank.
User clicks on "delete" button.

I use the following code when "delete" button is clicked:
===========================
If Me.Dirty = True Then Me.Dirty = False

If Me.NewRecord = -1 Then
MsgBox "New record--nothing to delete.", vbInformation, "No delete"
Exit Sub
End If

DeleteTheRecord 'call module & delete if they say yes
=====================================
If I don't "save" the record first using "If Me.Dirty = True Then Me.Dirty =
False", then newrecord is set to -1 and doesn't delete the record.

If I "save" the record using "If Me.Dirty = True Then Me.Dirty = False",
then it goes into my error handling routine because a required field is blank.

Any suggestions would be greatly appreciated.

(I'm using Access 2007)

If the user is on the new record then don't either save OR delete - Undo the
edits instead:

If Me.NewRecord Then
Me.Undo
Else
DeleteTheRecord
End If
 
L

laavista

Thanks to both of you. Great suggestions.

(I tried the me.undo, and it worked like a charm).

Thanks again!
 

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