Results 1 to 5 of 5
  1. #1
    Lori F is offline Novice
    Windows 11 Access 2019
    Join Date
    Jan 2024
    Posts
    12

    Run Time Error 424 on Save

    I have a field on a form that I want to validate. I did put a validation rule on that field, but I also want to put a validation when the Save button is clicked in case the user doesn't even go to the field. Every time I click on Save (and have left the field blank), I get a run time error 424. When I debug, the if statement in this event is in yellow. For the life of me, I can't figure out what the problem is. below is the code that seems to be throwing the error. Is the problem that I need to do it in a different event or is my code incorrect?



    Code:
    Private Sub SaveRecordBtn_Click()
    
    
    If Forms("EnterNewTransactions").Controls("PmtSource").Value Is Null Or _
        (Forms("EnterNewTransactions").Controls("PmtSource").Value <> "C" And _
        Forms("EnterNewTransactions").Controls("PmtSource").Value <> "K" And _
        Forms("EnterNewTransactions").Controls("PmtSource").Value <> "P" And _
        Forms("EnterNewTransactions").Controls("PmtSource").Value <> "O" And _
        Forms("EnterNewTransactions").Controls("PmtSource").Value <> "L") Then
        MsgBox "You must enter a valid payment source."
        Cancel = True
    Else
        DoCmd.Save
        TranDate.SetFocus
        DoCmd.GoToRecord , , acNewRec
    End If
    
    
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Might be the "Is Null", which is SQL syntax. Try

    IsNull(Forms("EnterNewTransactions").Controls("Pmt Source").Value)

    Also, data validation is typically done in the before update event of the form:

    https://www.baldyweb.com/BeforeUpdate.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    By the way, I'd probably make the payment source control a combo with limit to list set to yes, so only valid selections could be entered. Then you just test for Null.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Lori F is offline Novice
    Windows 11 Access 2019
    Join Date
    Jan 2024
    Posts
    12
    Thanks for the advice. That worked. Have a blessed day.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 09-02-2017, 01:49 PM
  2. Hoping someone can save me a ton of time.
    By redbull in forum Access
    Replies: 2
    Last Post: 10-30-2013, 10:45 PM
  3. "You can't save this record at this time" error
    By kelann in forum Programming
    Replies: 4
    Last Post: 10-29-2012, 02:21 PM
  4. Every time I close or save changes
    By Opid in forum Access
    Replies: 1
    Last Post: 06-18-2012, 07:43 AM
  5. Replies: 2
    Last Post: 01-05-2012, 04:23 AM

Tags for this Thread

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