Clearing invalid date from a combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Petrol
    Contributor
    • Oct 2016
    • 251

    Clearing invalid date from a combo box

    I have a form with several combo boxes, all with Limit to List on. If a user enters invalid data into one of them, of course he gets the "not in list" message. If he then decides he was on the wrong track and tries to cancel the form (Cancel button click event = Me.Undo), Access still keeps insisting on a valid entry in the combo box. I can't go back and clear it programmaticall y because the focus is now on the Cancel button and I can't tell which control caused the error or what its previous value was.
    Of course it is always possible (in fact, it is necessary) for the user to then delete the erroneous entry or randomly select an acceptable one before cancelling the form, but this is non-intuitive and a bit of a nuisance. Is there any way I can really undo and cancel the form in the Cancel button click event (other than saving all the values of all the controls when the form is opened and then restoring them one by one!)?
    Thanks for your help.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32636

    #2
    Hi Petrol.

    Are you sure that the code for the Cancel_Click() event is even being reached. I would not expect it to get that far if the ComboBox had no valid selection. The way to handle that would be either the simple <ESC> key or, if there's a valid event triggered by an invalid entry (I think there may be.), then put code in there to Undo() the control.

    Does that make sense?

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      There is a combobox.notinl ist event that you should consider using to reset the control.
      (https://learn.microsoft.com/en-us/of...obox.notinlist)
      In certain circumstances I use this event in several of my front-ends to add new entries to the allowed list and in others I cancel the entry and reset it to blank.
      Last edited by zmbd; Oct 23 '22, 02:46 AM.

      Comment

      • Petrol
        Contributor
        • Oct 2016
        • 251

        #4
        Thank you both; you're both right. I had forgotten there was a NotInList event.

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          Our pleasure
          If you run into a snag implementing this please feel free to post back to the thread
          =Z

          Comment

          Working...