Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleteRecord not available 1

Status
Not open for further replies.

hoofit

Technical User
Nov 20, 2005
343
US
I am receiving

The command or action 'DeleteRecord' isn't available now.

I am not sure why.

I am editing a database form that is using several tabs & several subforms are part of this form. I have tried to move the delete command button around with some success. Although the record I want to delete is on a subform, seems that the control needs to be on the main form to work. Is there a way to reference the control that I'm not doing correctly?

Thank you,

hoof
 
The control doesn't need to be on the main form for it to work but the subform has to have deletions allowed set to yes and the record source needs to be updateable. But what code are you trying to use and where have you put the delete button? On a continuous form I have put a button in the details section so it shows for every record. That way the current record I am deleting is selected. If you put it elsewhere you have to use code to go back to the record first to select it. So, if you have the button in the details section on a continuous form you can use:

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

And if you have the button on a different form, as long as you were in the record you want to delete you can use

Screen.PreviousControl.Select
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord


Or you can use a delete query and then requery the form.

Bob Larson
FORMER Microsoft Access MVP (2008-2009, 2009-2010)
Free Tutorials/Samples/Tools:
 
Howdy hoofit . . .

If you used the command button wizard to make the button you may have a focus problem.
[ol][li]If the button is on the subform you should have no problem (focus will be on the subform when you hit the button).[/li]
[li]If the button is on the mainform then you 1st have to set focus to the subform (focus is on the mainform when you hit the button). In this case replace the button code with the following:
Code:
[blue]   [[purple][B][I]YoursubFormName[/I][/B][/purple]].SetFocus
   DoCmd.RunCommand acCmdDeleteRecord
[/blue]
Without setting focus to the subform you'll be deleting records in the mainform, and depending how the subforms are linked ... a high possibility of subform records as well.[/li][/ol]
[blue]Your Thoughts? . . .[/blue]


See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Aceman1
FormName.SetFocus did it. Even though the delete button was on the subform, I still needed to set focus to it. Works nice. Thank you boblarson for checking in as well.

hoof
 
hoofit . . .

When your dealing with [blue]DoCmd[/blue] always keep [blue]focus[/blue] in mind ... a majority of the commands depend on it.

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Even though the delete button was on the subform, I still needed to set focus to it.
It is interesting because I've never used that and have had it work just fine for me before.

Bob Larson
FORMER Microsoft Access MVP (2008-2009, 2009-2010)
Free Tutorials/Samples/Tools:
 
hoofit said:
[blue]FormName.SetFocus did it. Even though the delete button was on the subform, [purple]I still needed to set focus to it.[/purple][/blue]
Hmmmm ... I have a problem with the quote text in [purple]purple[/purple]. Try the following in the button (assuming the button is on the subform).This should be the only code:
Code:
[blue]   DoCmd.RunCommand acCmdSelectRecord
   docmd.RunCommand acCmdDeleteRecord[/blue]

Let me know the results.

BTW: what version access are you using?

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I'm using 2002

Here's the code...

Private Sub PMAssignSub101DeletePM2_Button_Click()
frm_PMAssignSub101.SetFocus


On Error GoTo Err_PMAssignSub101DeletePM2_Button_Click

Dim DeleteButtonDialogResult As Integer

'If IsNull(UnitID) = True Then .....did not refer correctly here
'refer to the control correctly
If IsNull(Me!frm_PMAssignSub101.Form!UnitID) = True Then



MsgBox "No record has been selected for deletion"

Else
DeleteButtonDialogResult = MsgBox("Are you sure that you want to delete this record?. This process is irreversible and all data will be permanently lost!.", vbYesNo + vbQuestion, "Delete?")
If DeleteButtonDialogResult = 6 Then '6 = a yes

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Else

End If

Exit_PMAssignSub101DeletePM2_Button_Click:
Exit Sub

hoof
 
If IsNull(Me!frm_PMAssignSub101.Form!UnitID) = True Then
So, the button isn't in the frm_PMAssignSub101 subform but in its parent form.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top