Cancel listbox selection

  • Thread starter Thread starter vba-dev
  • Start date Start date
V

vba-dev

I have a form with one listbox and one subform control.

Listbox contains list of reports. Subform control contains an options form
for whichever report is selected in the listbox. None of the forms are bound.

When I select a report, the child subform loads an appropriate class object.
The class has a dirty property and an event, which fires of course when the
object is dirty.

If the object is dirty, I want to prevent user from selecting a different
report, unless the current report is saved first.

I am attempting to use the BeforeUpdate event of the listbox. Seems to work
ok, but if I set Cancel = True, the subform is locked unless I hit Escape. I
do not want to code a SendKeys.

Does anyone have a nice, clean way of handling such a thing? Thanks.
 
vba-dev said:
I have a form with one listbox and one subform control.

Listbox contains list of reports. Subform control contains an options form
for whichever report is selected in the listbox. None of the forms are bound.

When I select a report, the child subform loads an appropriate class object.
The class has a dirty property and an event, which fires of course when the
object is dirty.

If the object is dirty, I want to prevent user from selecting a different
report, unless the current report is saved first.

I am attempting to use the BeforeUpdate event of the listbox. Seems to work
ok, but if I set Cancel = True, the subform is locked unless I hit Escape. I
do not want to code a SendKeys.


I thin the problem is that you can not set a control's value
in the BeforeUpdate event. If the list box is bound, you
can undo it, but the value is in the process of being
updated so you can't change it until the AfterUpdate event.

I think it would be much simpler to use the subform Dirty
event to disable the mainform list box:
Parent.listbox.Enabled - False
Re-enable it when the report is processed.
 
Thanks, Marshall. That's a decent approach, though probably not something I'd
like to see on this form.

The code I'm using now works well, except for a minor hiccup. Without
sending an Esc to the screen, I can't figure out how to return the listbox
selection to the previous one.

For now, I've given up, and am using SendKeys. Thanks.
 
Back
Top