[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Capture a button onclick event from field onexit event?

Posted on 2005-04-21
12
Medium Priority
?
440 Views
Last Modified: 2011-09-20
I have a form that has several fields that are required to be filled, if certain other fields have values.  I trigger a message box at the onexit event of these required fields, if the first field has a value and the required field doesn't contain any values.  My problem is that if the user partially fills out the form, gets to one of these required fields and decides to bail out of the form (close), the onexit event of the required field is triggered before the onclick event of the close button and my popup message is displayed before the form closes.  This isn't fatal, but it is annoying.  Is there a way to capture the onclick event of the close button at the onexit event of the field so I can bypass the message box?  I hope I have explained this clearly.
0
Comment
Question by:cswebdev
11 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 13834234
Hi cswebdev,

The answer to your question is NO.
The alternative approach is not to use the Control events but to use the Form_Beforeupdate event procedure to do all of the tests and report the problems there.
(Using
Cancel = true
in the beforeupdate procedure stops the record being saved)

Pete
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 13834349
In your button's OnClick event, have you tried including "Me.Undo" to cancel any changes to the current record?  
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 13834523
Here is one approach that might work for you:

In the form (at the top), declare a Boolean flag:

    Private fCancel As Boolean

In the Form_Load event, set the flag to false:

    fCancel = False

In the button OnClick event, set the flag to true:

    fCancel = True

In the OnExit events, check the flag:

    If Not fCancel Then
        ' check for required fields
    End If

I hope that will work for you.

Chuck
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:cswebdev
ID: 13835584
Pete and routinet, thank you for your responses.  Chuck, your solution works perfectly!  Thank you.
0
 

Author Comment

by:cswebdev
ID: 13835842
Ooops.........Sorry Chuck, it didn't work the second time I tried it.  Apparently the first time I tried your code, I had already tried to close the form, canceled the action and the flag was set to true.  So, then my onexit routine worked.  However, since the flag doesn't get set to true until the button onclick event, at the onexit event the flag is false and I still get the message box.  I need to try something else.
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 13836344
OK, I see how that would work. Here is what I would do:

1. Move all of the required field checks from the OnExit events to the Close button OnClick event.

If Not IsNull(txtBox1) And Len(Trim(txtBox1)) > 0 And (IsNull(txtBox2) Or Len(Trim(txtBox2)) = 0) Then
    MsgBox "You must fill in txtBox2"
    txtBox2.SetFocus
    Exit Sub
End If
'  repeat for every required field

2. Create a Cancel button that closes the form but does not run the required field checks.

I realize that this does not work exactly as it did before but I think it will provide a more pleasing user interface.

Regards,

Chuck
0
 

Author Comment

by:cswebdev
ID: 13836711
Thank you Chuck.  That is what I am going to have to do.  I just can't check for required fill at each field.  It will have to be a seperate sub at some point.  The form is being used to build a query to produce a report and my checks will have to be attached to my "Show Report" button instead of as the fields are filled.  I had hoped I could force the user to fill all required fields before trying to build the report, but I guess not.
0
 
LVL 16

Accepted Solution

by:
Chuck Wood earned 2000 total points
ID: 13836816
I had another thought while at lunch.

As an alternative, you could build the Sub and run it from the OnEnter event of each of the text boxes, but not in the Close button. That way, if you were in a text box, you could exit it when the Close button is pressed without triggering the check but, if you entered another text box, you would trigger the check. You would also probably want to trigger the check sub when the Show Report button is pressed.

Chuck
0
 

Author Comment

by:cswebdev
ID: 13837016
I think I will try your last suggestion.  I really want the user to have all the required fields filled before trying to submit for report.  I will let you know what happens.  Thanks.
0
 

Author Comment

by:cswebdev
ID: 13842345
Chuck, your last suggestion seems to have done the trick.  I created a sub to validate/check all required fields.  That sub is invoked whenever I need to check for an entry and so far my testing seems to indicate it is working as needed.  I thank you very much for your help.
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 13842737
You are welcome.

Good luck on your project.

Chuck
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

868 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