Re: Repost: DoCmd.RunCommand acCmdDeleteRecord does nothing.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



If you are seeing that error, it must be due to the fact the the control
currently contains an invalid or unacceptable entry (such as an incomplete
date, text where a number should be, or the entry back-spaced out in a
required control.) As a result, it never even starts to process the code in
the button, because they can't reach the button: they are stuck in the
control with the bad entry.

The simplest solution is to teach the user to press the Esc key to cancel
the entry they were making. If that's too difficult to remember, they can
press the Undo button on the toolbar, or choose Undo from the Edit menu.

Once they undo that control, they will be able to get to the button to run
its code.

If you think it would help, it is possible to build a custom toolbar and add
your own Undo/Delete button there. The user can get to the toolbar, since it
is not a button on their form.

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

"Paolo" <paolo@xxxxxxxxxxxxxx> wrote in message
news:1153238133.663252.149900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi Allen,

Thanks for the tip as you can see I am very new to this. Further on
this topic:

I have a delete button which deletes records on a form. I use the
following code (with your advice). Unfortunately, if the user is going
to delete a record with a required field set to null, the form's error
message kicks in saying that the field needs a required value. Any
ideas as to how I can get the field to be undone and then deleted (if
it's not a new record)?

Thanks in advance,

Paolo


Private Sub Command2_Click()
On Error GoTo ErrHandler
Beep
If MsgBox("Are you sure you want to delete the record?", _
vbQuestion + vbYesNo, "Delete?") = vbYes Then
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
DoCmd.RunCommand acCmdDeleteRecord
End If
End If
Command2_Click_Exit:
Exit Sub
ErrHandler:
Select Case Err.Number
Case 3200
MsgBox "Employee ID is referenced in another form!",
vbCritical, _
"Referential Integrity Error"
Me.Undo
Case Else
MsgBox "Error in Command2_Click()." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf &
Err.Description
End Select
Err.Clear
Resume Command2_Click_Exit
End Sub
Allen Browne wrote:
You cannot delete the record before it is saved. The approaches you are
using attempt to save the record before it is deleted, and the messages
associated with the failed save differ (or don't exist.)

If you don't want the record, it makes sense to undo any edits in
progress.
You can then delete the record if it exists:
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
DoCmd.RunCommand acCmdDeleteRecord
End If

That gives no error if the record can't be saved because it is invalid,
and
also avoids the error message if there is no record to delete.
(Presumably
there is no point telling the user that the record cannot be saved, since
they want to be rid of it anyway.)


"vainglory" <paolo@xxxxxxxxxxxxxx> wrote in message
news:1153205796.488374.284650@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

Sorry for the repost, but I didn't get any comments regarding this:

I was revising my code as recommended to avoid using:

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

and use:

DoCmd.RunCommand acCmdDeleteRecord

But as soon as I did, I noticed that my delete button seemed to die.
That is, whenever I violate referential integrity, or attempt to delete

a record that has nulls in a required field or primary key or has
duplicates in a primary key I get no error whatsoever! In fact,
nothing happens! Is this normal? I don't even get warning message
even though warnings is turned on.

Then, I replaced:

DoCmd.RunCommand acCmdDeleteRecord

with

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

and I got my error messages back. But strangely, I still have no
warning
messages. Please I am dying of curiosity as to why this is happening.
Any ideas?


.



Relevant Pages

  • Re: Cant preset or close a form because of "required" property
    ... If the control is bound to a Required field, and the user deletes the entry, ... Access won't let them out of that control. ... If that's too hard for them, they could learn to use the Undo button on the ...
    (microsoft.public.access.forms)
  • Re: Problem with Return Value from a Function
    ... The function reference transfers control to a function procedure; the function procedure returns control and a value, which replaces the function reference in the evaluation of the expression. ... ENTRY variables cannot be returned unless they have the LIMITED attribute. ... The CALL statement can be used to invoke it only if the returned value has the OPTIONAL attribute. ...
    (comp.lang.pl1)
  • Re: "prompted selection" ?
    ... The behavior you described is controlled by the .MatchEntry property of the ... ComboBox or ListBox control. ... The control searches for the next entry that starts with the ... Extended matching. ...
    (microsoft.public.word.vba.userforms)
  • Re: Restricting subforms entry before mainform
    ... Next, in the property dialog box for the selected control, with the Events ... there should be an entry like the one below for each of the ... controls on your form except the AutoNumber field. ... before allowing data entry in the subform? ...
    (microsoft.public.access.forms)
  • RE: Lookup problems
    ... I was able to resolve this problem by doing the following: ... Remove the combo box control from the form. ... typing in an entry works, ... "Keith" wrote: ...
    (microsoft.public.access.forms)