Hello there,
I'm having trouble trying to reset unbound controls to their previous value. Right now I have a series of text fields, comboboxes and checkboxes that I want to use as filter selectors for an individual form. I have some custom record navigation buttons that cycle the records that fit the selected filters. The filter (or combination of filters) applies well, but I want to add the following functionality. If a user selects a new value on a filter selector (be it a combobox, text field or whatever) and the resulting filter would yield no records, I want to leave the remaining controls as they were, revert the modified control to its previous value and leave the filter untouched. So the obvious choice seemed like a beforeupdate event for each control. When any filter field is changed, the beforeupdate event calls a custom function that sets up the whole filter query and checks if any record matches it. If so, it stores the filter query in a variable (since it wouldn't let me apply the filter during a beforeupdate event) and returns a 0 value to the beforeupdate event. If not, it returns a 1 value. Then the afterupdate event (if triggered) calls the filter sub that applies the filter stored in the variable.
The beforeupdate event looks like this:
The cancel bit is working since the afterupdate doesn't get triggered, but the .undo isn't reverting the value to whatever it was before, thus making the combobox or textfield show a value different to the one corresponding to the current filter.Code:Private Sub filtro_modelo_BeforeUpdate(Cancel As Integer) If checkFiltro = 1 Then Me.filtro_modelo.Undo Cancel = True End If End Sub
Any idea why the .undo doesn't work? Is there any other way to get the desired result other than doing it manually passing it in a variable or something?
Thank you very much!