By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

delete a record with required fields

P: n/a
i have a form that has required fields and i have a delete button, created by
the wizard, that has this code for onclick:

Private Sub cmddeleterecord_Click()
On Error GoTo Err_cmddeleterecord_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_cmddeleterecord_Click:
Exit Sub

Err_cmddeleterecord_Click:
MsgBox Err.Description
Resume Exit_cmddeleterecord_Click
End Sub

5 of the 9 fields on this form are required. if you try to delete the record
w/o filling in all of these fields, access won't let you. how can i bypass
this and allow a user to click the delete button and either delete the
incomplete record or clear the form? thanks.

--
Message posted via http://www.accessmonster.com
Nov 29 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Press the Esc key twice to undo the record.

You will then be able to move focus to the Delete button (which won't do
anything helpful if you are already at a new record.)

--
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.

"ka******@comcast.net via AccessMonster.com" <u15580@uwe> wrote in message
news:580f139eb3d96@uwe...
i have a form that has required fields and i have a delete button, created
by
the wizard, that has this code for onclick:

Private Sub cmddeleterecord_Click()
On Error GoTo Err_cmddeleterecord_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_cmddeleterecord_Click:
Exit Sub

Err_cmddeleterecord_Click:
MsgBox Err.Description
Resume Exit_cmddeleterecord_Click
End Sub

5 of the 9 fields on this form are required. if you try to delete the
record
w/o filling in all of these fields, access won't let you. how can i
bypass
this and allow a user to click the delete button and either delete the
incomplete record or clear the form? thanks.

Nov 29 '05 #2

P: n/a
Quick and dirty solution:

Private Sub cmddeleterecord_Click()
if isnull(me.requiredField1) or isnull(me.requiredField2) then
'this is an as yet unsaved record because
'record will not save if required field is missing.
'simply re-set (undo) to empty all fields.
me.undo
else
'delete the record
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
end if
End Sub

Then add "is not null" to the validation property of the required
fields to make sure that users cant set them to null on an already
existing record - otherwise there could be a loop-hole in the above
code.

Nov 29 '05 #3

P: n/a
thank you. that is EXACTLY what i was looking for. perfect.

greg

BillCo wrote:
Quick and dirty solution:

Private Sub cmddeleterecord_Click()
if isnull(me.requiredField1) or isnull(me.requiredField2) then
'this is an as yet unsaved record because
'record will not save if required field is missing.
'simply re-set (undo) to empty all fields.
me.undo
else
'delete the record
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
end if
End Sub

Then add "is not null" to the validation property of the required
fields to make sure that users cant set them to null on an already
existing record - otherwise there could be a loop-hole in the above
code.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200511/1
Nov 29 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.