Cannot delete selected rows with push of a button in subform datasheet view.

I have set the allowdeletions propety default to false, as I dont want users to highlight and hit delete by them selves.

I wish to do the following

have a button that does this :

but i get a runtime error 2406
"The comamnd or action deleterows isn't available now"  any ideas...


Forms![purchaseorders]![PurchaseOrdersSubform].Form.AllowDeletions = True
Forms![purchaseorders]![PurchaseOrdersSubform].Form![ProductID].SetFocus
 DoCmd.RunCommand acCmdDeleteRows
Forms![purchaseorders]![PurchaseOrdersSubform].Form.AllowDeletions = False
...plus some other code....
Ricky11Asked:
Who is Participating?
 
harfangCommented:
Hello,

You are using the wrong constant. It's acCmdDeleteRecord, not acCmdDeleteRows...

Try this:

    Me.PurchaseOrdersSubform.SetFocus
    With Me.PurchaseOrdersSubform.Form
        .AllowDeletions = True
        RunCommand acCmdDeleteRecord
        .AllowDeletions = False
    End With

But the really simple solution is just:

    Me.PurchaseOrdersSubform.Form.Recordset.Delete
    Me.PurchaseOrdersSubform.SetFocus

Cheers!
(°v°)
0
 
RgGray3Commented:
Please clarify...  you want a button to do the deletion?

If so simply place a button on the detail record
and write a Delete SQL statement and build the where portion in the on click

Assuming that yor details are in a table called PurchaseOrdersDetails it would be something like the following

Dim strSQL as string

strSQL = "Delete * from PurchaseOrdersDetails Where InvoiceNum = " & Me.invoiceNum & " AND ProductID = " & Me.ProductID & ";"

DoCmd.RunSQL strSQL

Me.requery

The form properties have no control to prevent you from running SQL

Rich

0
 
Ricky11Author Commented:
Still cant manage to do it.

I need to delete only the selected row in the the subform datasheet view.


the delete button is comming from another form on the main form..

thus in my original question i had done as follows


Forms![purchaseorders]![PurchaseOrdersSubform].Form![ProductID].SetFocus
 DoCmd.RunCommand acCmdDeleteRows
Forms![purchaseorders]![PurchaseOrdersSubform].Form.AllowDeletions = False

i can see that the focus has now change to the correct row on the datasheet subform but i am still getting the same error deleting it... and i dont think it has anything to do with the allow deletions property... cuz i change it to true in the original subform..

i will try and see if i can use a update query instead.

tks.

0
 
harfangCommented:
Hello,

You apparently haven't read my comment at {http:#16549990}. You are still using acCmdDeleteRows, which is wrong.
(°v°)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.