Before Update Event in Combo Box Cancel event

Posted on 2009-12-22
Last Modified: 2013-11-28
This is my code and attached are examples of errors I get.
Statement "Cancel = True" is causing the problem.

Error1 happens only in this example, but Error2 happens in all my combo boxes on various forms throughout the project where I have Cancel = True in the Before Update Event.

Private Sub Client_ID_BeforeUpdate(Cancel As Integer)

    If Nz(DLookup("[Client ID]", "[tblAttendance]", "[Session ID] = " & _
        Nz(Forms![frmSessionAttendance].Form.Recordset.[Session ID], 0) & _
        "AND [Client ID] = " & Nz(Me.[Client ID], 0)), 0) <> 0 Then
        MsgBox "This client already exists on this list."
        Cancel = True
    End If
End Sub

Question by:dpokerbear
    LVL 39

    Accepted Solution

    If you cancel the before update event of a control then you also need to cancel the form before update event and handle the form undo event. See, "Check for required items" for details on how to do it.

    Author Closing Comment

    LVL 39

    Expert Comment

    You're welcome.  Glad to help and thank you very much for the points with "A" grade!

    Happy computing!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    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…
    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now