?
Solved

Textbox OnExit Event cancels out CmdButton Click Event in Access 2003

Posted on 2005-03-01
10
Medium Priority
?
526 Views
Last Modified: 2012-05-05
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
Comment
Question by:tcalbaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 13432318
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
 
LVL 66

Expert Comment

by:Jim Horn
ID: 13432360
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
 
LVL 66

Expert Comment

by:Jim Horn
ID: 13432371
(Off Topic) wb Shane.  Great, now I won't be able to answer any questions for awhile..  ;)
0
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 13432395
(OT) Thanks Jim. I'll be sure to leave a few for you :-)
0
 
LVL 1

Author Comment

by:tcalbaz
ID: 13432489
*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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 13432531
Can you post the code of your OnExit event?
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 13432549
(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
 
LVL 1

Author Comment

by:tcalbaz
ID: 13432885
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
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 2000 total points
ID: 13432929
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
 
LVL 1

Author Comment

by:tcalbaz
ID: 13434014
shanesuebsahakarn
that did it!  thank you!

ted
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question