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

Posted on 2006-04-26
Last Modified: 2007-12-19
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
 DoCmd.RunCommand acCmdDeleteRows
Forms![purchaseorders]![PurchaseOrdersSubform].Form.AllowDeletions = False some other code....
Question by:Ricky11
    LVL 11

    Expert Comment

    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


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


    LVL 58

    Accepted Solution


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

    Try this:

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

    But the really simple solution is just:



    Author Comment

    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

     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.


    LVL 58

    Expert Comment


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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now