question

JamesGarrison-3189 avatar image
0 Votes"
JamesGarrison-3189 asked thedbguy answered

CheckBox BeforeUpdate Cancel leaves focus stuck on the control

If in a CheckBox BeforeUpdate event procedure I ask for the event to be cancelled, I expect that the control will be reset to its original value and not be considered dirty.

What actually happens is that, even though the UI shows the control has been reset, Access seems to think it's dirty and thus focus is stuck in that control. Any attempt to leave the control triggers BeforeUpdate, leaving me stuck in a loop.

The use case is this:

  1. User clicks a checkbox to toggle it

  2. The BeforeUpdate procedure displays an InputBox to ask for a password

  3. If the user cancels out of the InputBox, the returned value from InputBox is an empty string

  4. My code sees the empty string, which it interprets as a "cancel" request

  5. I set Cancel=-1 and exit the BeforeUpdate procedure

  6. The UI displays the old (unchecked value)

  7. Focus remains on the checkbox

Any further operation, such as attempting to move to a different field, re-triggers BeforeUpdate, and there does not seem to be a way out.

I tried Me.Undo with no effect.

Suggestions?

office-access-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

thedbguy avatar image
0 Votes"
thedbguy answered

Hi. Canceling an event is just that, it stops the event from running through completion. It doesn't reset the control automatically. To do that, you'll have to call the Undo method of the control. For example,

Me.CheckboxName.Undo

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.