tcalbaz
asked on
Textbox OnExit Event cancels out CmdButton Click Event in Access 2003
Hi Guru's!
Im a little confused about the priority of events in an access 2003 form I have. I have a textbox that performs a little validation when a user navigates out of the textbox field with the OnExit Event. However if the User presses a command button elsewhere on the form only the Textbox OnExit Event will fire but the Command Button Click Event will not run. It's almost as if the Command Button Click Event was cancelled.
The behavior that I want is that if a user navigates out of my textbox the TextBox OnExit Event fires. However if the User clicks on a command button - that command button's OnClick Event has priority and fires.
Any ideas / suggestions?
Thank You,
Ted
Im a little confused about the priority of events in an access 2003 form I have. I have a textbox that performs a little validation when a user navigates out of the textbox field with the OnExit Event. However if the User presses a command button elsewhere on the form only the Textbox OnExit Event will fire but the Command Button Click Event will not run. It's almost as if the Command Button Click Event was cancelled.
The behavior that I want is that if a user navigates out of my textbox the TextBox OnExit Event fires. However if the User clicks on a command button - that command button's OnClick Event has priority and fires.
Any ideas / suggestions?
Thank You,
Ted
I was able to successfuly demo this in Access 2003.
Make sure your button's .OnClick event is successfully attached to your button. In VBA code behind the form, do a right-click:Properties on your button and make sure you see [Event Procedure] in the OnClick property(event). Either way, click once within the OnClick property(event), then click on the button with the three dots to the right of it, and make sure that when you are dumped into code view, your code is in the .OnClick event.
Sometimes when you rename controls, or if you copy/paste a control with event code from one form to another, the code will not be attached to the button.
Hope this helps.
-Jim
Make sure your button's .OnClick event is successfully attached to your button. In VBA code behind the form, do a right-click:Properties on your button and make sure you see [Event Procedure] in the OnClick property(event). Either way, click once within the OnClick property(event), then click on the button with the three dots to the right of it, and make sure that when you are dumped into code view, your code is in the .OnClick event.
Sometimes when you rename controls, or if you copy/paste a control with event code from one form to another, the code will not be attached to the button.
Hope this helps.
-Jim
(Off Topic) wb Shane. Great, now I won't be able to answer any questions for awhile.. ;)
(OT) Thanks Jim. I'll be sure to leave a few for you :-)
ASKER
*shanesuebsahakarn*
The OnExit event takes the sales order number entered in the text box and then populates the form.
This is so that a user can manually enter a sales order number if they chose to. Otherwise clicking on the Command Button allows the user to bring up a pop-up selection box to select a sales order number.
If the user is at any other control on the form then the command box will work when clicked on.
*jimhorn*
Thanks - that is a valid point to check up on. However in this case the Command Buttons On Click event appears to be rigged correctly and will fire when the cursor is located at any other control.
Keep those ideas coming guys,
Thank you
Ted
The OnExit event takes the sales order number entered in the text box and then populates the form.
This is so that a user can manually enter a sales order number if they chose to. Otherwise clicking on the Command Button allows the user to bring up a pop-up selection box to select a sales order number.
If the user is at any other control on the form then the command box will work when clicked on.
*jimhorn*
Thanks - that is a valid point to check up on. However in this case the Command Buttons On Click event appears to be rigged correctly and will fire when the cursor is located at any other control.
Keep those ideas coming guys,
Thank you
Ted
Can you post the code of your OnExit event?
(potentially stupid answer) You can't have your CommandButton.Click fire conditionally, i.e. whether it happens by TextBox.OnExit, or other means. If you want to 'override' a control event (1) if the user performs another control event (2) , then you'll likely have to create a form-level variable, say bOverride, and in (1) set it to True, then in (2) you can test bOverride, and execute code according to your wishes.
ASKER
Question:
Are there any other textbox events that will allow me to perform a validation/populate form when leaving the textbox without interferring with the command button?
Ted
Are there any other textbox events that will allow me to perform a validation/populate form when leaving the textbox without interferring with the command button?
Ted
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
shanesuebsahakarn
that did it! thank you!
ted
that did it! thank you!
ted
What does your OnExit do?