ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Exit Field vs Exit Button...... (https://www.excelbanter.com/excel-programming/399020-exit-field-vs-exit-button.html)

roy_ware

Exit Field vs Exit Button......
 
Just hit a weird one he I'm working with data validation on a form. The
first field on this for is a "must fill" and I check this with an event:

Private Sub txtName_Exit(ByVal Cancel As MSForms.ReturnBoolean)
if txtName.Value = "" then
error message stuff


When I hit the button to exit the screen, I expect to execute the following
code:

Private Sub ExitButton_Click()
Unload Me
MainMenu.Show
End Sub

But!!! If the cursor is positioned on the Name field, execution goes to the
txdtName_Exit routine before exiting!

I've been searching for an event to capture this and bypass the error
message, but have had no luck so far.

Suggestions?????


Bill Renaud

Exit Field vs Exit Button......
 
<<If the cursor is positioned on the Name field, execution goes to the
txdtName_Exit routine before exiting!

This is probably because the focus on the form is exiting the Name field to
go to the Exit button.

Maybe you could just move the code from the txtName_Exit routine to the
ExitButton_Click routine. Do you really need to check the value the moment
the user leaves the field to change something else. Maybe they are going to
come back and correct the Name field before finalizing their input anyway.
Or is the Name field required to be correct before other fields can be set
properly?

--
Regards,
Bill Renaud




ISS6

Exit Field vs Exit Button......
 
Yes, this name field is required and the edit logic was built on the idea
that there was no point in continuing to other fields when the "#1" field was
incorrect.

I was hoping that there would be some control I could test within the name
edit routine to check if the even was triggered when the Exit button had been
pressed. That would greatly simplify things, but I haven't been able to find
the right condition.

I know it must be there - just out of the grasp of my feeble mind.......

"Bill Renaud" wrote:

<<If the cursor is positioned on the Name field, execution goes to the
txdtName_Exit routine before exiting!

This is probably because the focus on the form is exiting the Name field to
go to the Exit button.

Maybe you could just move the code from the txtName_Exit routine to the
ExitButton_Click routine. Do you really need to check the value the moment
the user leaves the field to change something else. Maybe they are going to
come back and correct the Name field before finalizing their input anyway.
Or is the Name field required to be correct before other fields can be set
properly?

--
Regards,
Bill Renaud






All times are GMT +1. The time now is 08:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com