Results 1 to 4 of 4
  1. #1
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212

    Error 2501

    I am using the following:

    Code:
    Private Sub PurchasePrice_LostFocus()
    DoCmd.RunCommand acCmdSaveRecord
    End Sub
    In the case where a record is not yet created, I get

    Runtime error 2501
    The Runcommand action was cancelled.

    I'm thinking that the least change I can make to this code, is to put

    On Error Resume Next before the DoCmd line

    Will this work?

    Thanks for any input.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Better would be to prevent the error.

    If Me.Dirty Then
    DoCmd.RunCommand acCmdSaveRecord
    End If

    or

    If Me.Dirty Then Me.Dirty = False

    Record entry/edit is committed to table when move to another record or close table/query/form or run code.

    Why do you need to save record just because control loses focus?
    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
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I would probably use the PurchasePrice_AfterUpdate.

    Also, you can check if the Value of PurchasePrice is Null.

    I think something like this would work ...

    Private Sub PurchasePrice_AfterUpdate()

    if isnull(Me.PurchasePrice.Value) = False then
    DoCmd.RunCommand acCmdSaveRecord
    end if

    end sub

  4. #4
    Abacus1234 is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    212
    Thanks for the suggestion. Under some circumstances the form stays open as a reference to other forms being opened. I do not commonly move to another record.

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

Similar Threads

  1. Runtime Error 2501 on docmd.runSQL
    By schwachmama in forum Access
    Replies: 5
    Last Post: 04-17-2015, 11:28 AM
  2. Do.cmd OutputTo Error 2501
    By Fuzz_cozens in forum Programming
    Replies: 7
    Last Post: 07-15-2014, 06:44 AM
  3. Error Handling 2501
    By RainyDay in forum Programming
    Replies: 7
    Last Post: 06-08-2013, 10:44 PM
  4. Suppressed run time error 2501
    By RachelBedi in forum Programming
    Replies: 8
    Last Post: 10-24-2012, 12:26 PM
  5. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM

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