DeleteRecord error on an open form

  • Thread starter Thread starter Ben
  • Start date Start date
B

Ben

Hi guys,

I designed a database and tested it all, and it seemed to work. However, a
problem has come to light, which I am one hundred percent positive was not a
problem before!

To get to this form, a button is clicked on the main form. It is password
protected, so when the correct password is entered, up pops the form. There
are two buttons available. One to add a category, and one to delete an
existing category. All the categories are on show in a subform next to
these buttons.

The problem I am having is selecting a category to delete and pressing the
delete button. The code for it is shown below. When I click the delete
button, I get this error: The command or action 'DeleteRecord' isn't
available now.

Can somebody please help in telling me how I get my code to delete the
selected record properly?

Thanks very much all,

Ben

----------------------------
Private Sub DeleteCategoryAdmin_Click()
On Error GoTo Err_DeleteCategoryAdmin_Click
DoCmd.SetWarnings False
If MsgBox("Are you sure you want to delete this category?", vbQuestion +
vbYesNo, "Delete Category") = vbYes Then
Forms!Admin!AdminCategoriesSubform.SetFocus
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
Forms!Admin!AdminCategoriesSubform.Requery
End If

Exit_DeleteCategoryAdmin_Click:
Exit Sub

Err_DeleteCategoryAdmin_Click:
MsgBox Err.Description
Resume Exit_DeleteCategoryAdmin_Click

End Sub
--------------------------------
 
Is the Enabled property of the embedded subform (within
its parent) set to false to prevent people entering data
directly? Or perhaps the Data properties (AllowEdits,
AllowDeletions, etc.) are set to prevent editing? Any of
these reasons will prevent the action from ocurring since
the code you are using emulates the user interface.

A better solution to the problem is to read the primary
key of the currently selected record from the subform and
then use it to execute a parametised query that deletes
the record; then execute the Requery command on the
subform to refresh the data.
 
Is this a popup form?

If so, you may like to try deleting from the form's RecorsetClone, as the
menu items will not be available.

Dim rs As DAO.Recordset
With Me!AdminCategoriesSubform.Form
If .NewRecord Then
Beep
Else
Set rs = .RecordsetClone
rs.Bookmark = .Bookmark
If MsgBox("Really delete?", vbOkCancel) = vbOk Then
rs.Delete
end If
End If
End With
Set rs = Nothing
 
Thanks so much Allen. That worked a treat!

Ben

Allen Browne said:
Is this a popup form?

If so, you may like to try deleting from the form's RecorsetClone, as the
menu items will not be available.

Dim rs As DAO.Recordset
With Me!AdminCategoriesSubform.Form
If .NewRecord Then
Beep
Else
Set rs = .RecordsetClone
rs.Bookmark = .Bookmark
If MsgBox("Really delete?", vbOkCancel) = vbOk Then
rs.Delete
end If
End If
End With
Set rs = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to the newsgroup. (Email address has spurious "_SpamTrap")

However, not
 
Back
Top