PRB: No Validate Event When Activating CommandButton (189923)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q189923 SYMPTOMS
On a form in Visual Basic, you have a CommandButton whose CausesValidation
property is True. Also, the CommandButton's Default or Cancel properties
are True. The Default and Cancel properties allow you to activate the
CommandButton by pressing the ENTER or ESC keys. When you activate the
CommandButton by pressing ENTER or ESC, the Validate event for the current
control does not occur and the Click event of the CommandButton fires. This
may cause undesirable results if you need the Validate event for the
current control to occur before the Click event of the CommandButton.
If you activate the CommandButton using the mouse or the CommandButton's
accelerator key, the Validate event for the current control occurs as
expected.
CAUSE
When you activate a "default" or "cancel" CommandButton by pressing the
ENTER or ESC keys, focus does not change to the CommandButton. Because
Focus remains in the current control, the Validate event for the current
control does not occur. In short, the CausesValidation property for a
Default or Cancel CommandButton is ignored when you activate the
CommandButton by pressing the ENTER or ESC keys.
RESOLUTION
To work around this limitation when using Default or Cancel CommandButtons,
you must add your validation code to the Click event of the CommandButton.
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 5/13/2003 |
---|
Keywords: | kbprb KB189923 |
---|
|