Results 1 to 5 of 5
  1. #1
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250

    Runtime 2501: Run Command Action was canceled while deleting subform record

    Hello,

    I have a continuous subform for Order Details. I want to have a "Delete" button next to each record, which deletes this record. I don't like the default record selectors.

    I have this code:
    Code:
    Private Sub cmdDeleteItem_Click()
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.SetWarnings True
    End Sub
    However I get this error while executing the "DoCmd.RunCommand acCmdDeleteRecord":
    Runtime error 2501: Run Command Action was canceled.

    The same thing happens when I use the button wizard and tell it to delete the record (hence, using a macro).



    Deleting the record like this works just fine:
    (I connect to Microsoft SQL Server and execute the command there via ADO)
    Code:
    Private Sub cmdDeleteItem_Click()
        Connect
        Exec "DELETE FROM tbl1PurchaseOrderDetails WHERE PurchaseOrderDetailID=" & Me.PurchaseOrderDetailID
        Disconnect
    End Sub
    Can you please advise where might be the problem? Thank you.
    Tomas

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    I tested and it works for me. I don't see anything wrong with code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I have this code:
    Where is the code? On the main form perhaps?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Also make sure the form's Allow Deletions property is Yes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Thomasso is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Nov 2016
    Location
    Czech Republic
    Posts
    250
    Code is in the subform, allow deletions is set to Yes.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 10-21-2014, 12:25 PM
  2. runtime error 2501 openform action was canceled
    By rumenrs in forum Programming
    Replies: 2
    Last Post: 04-11-2013, 04:29 AM
  3. Replies: 6
    Last Post: 11-28-2012, 03:43 PM
  4. Replies: 15
    Last Post: 07-26-2012, 02:06 PM
  5. Replies: 7
    Last Post: 07-18-2012, 07:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums