Link to home
Start Free TrialLog in
Avatar of Ricky11
Ricky11

asked on

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....
Avatar of RgGray3
RgGray3

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

ASKER CERTIFIED SOLUTION
Avatar of harfang
harfang
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ricky11

ASKER

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.

Hello,

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