• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

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
0
tcalbaz
Asked:
tcalbaz
  • 4
  • 3
  • 3
1 Solution
 
shanesuebsahakarnCommented:
The OnExit event will execute first. This is because, when the user clicks on your command button, the focus leaves the textbox (that is, the textbox is exitted), the focus enter the command button and then the button is clicked.

What does your OnExit do?
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
(Off Topic) wb Shane.  Great, now I won't be able to answer any questions for awhile..  ;)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
shanesuebsahakarnCommented:
(OT) Thanks Jim. I'll be sure to leave a few for you :-)
0
 
tcalbazAuthor Commented:
*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
0
 
shanesuebsahakarnCommented:
Can you post the code of your OnExit event?
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
(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.
0
 
tcalbazAuthor Commented:
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
0
 
shanesuebsahakarnCommented:
Yes - you could try using the AfterUpdate event instead. This will only fire when the text box's data is changed. Try that and see if it resolves your problem.
0
 
tcalbazAuthor Commented:
shanesuebsahakarn
that did it!  thank you!

ted
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now