Suppress focus events of a textbox control in Validating event

H

Hamed

Hello

I have a Data Entry Form having some controls including a TextBox. When the
user types an entry, I query a table and if it was entered before, I ask the
user (using ShowModal method of a custom message form) if he wants to see
his old entry in a new form. if he/she choose Yes, I create a new form and
show the previously entered data in it.

The problem is when I create and show the new form, the validating event is
fired two times and so it asks again if the user wants to see previously
entered data.


The application is an MDI application.

Please help me what am I wrong with.


Regards
Hamed
 
M

Mr. Arnold

Hamed said:
Hello

I have a Data Entry Form having some controls including a TextBox. When
the user types an entry, I query a table and if it was entered before, I
ask the user (using ShowModal method of a custom message form) if he wants
to see his old entry in a new form. if he/she choose Yes, I create a new
form and show the previously entered data in it.

The problem is when I create and show the new form, the is fired two times
and so it asks again if the user wants to see previously entered data.


The application is an MDI application.

Please help me what am I wrong with.

Why don't you pass a local scope Boolean flag in the form's constructor, and
at the validating event check the flag, if the Boolean flag is true bypass
code/exit or else execute the code and exit?
 
H

Hamed

The Validating event of the first form is fired twice not the second form.

I think there is some interference between focus events and ShowModal
method.

Please help. Am I wrong in using the Validating routines?

Hamed
 
M

Mr. Arnold

Hamed said:
The Validating event of the first form is fired twice not the second form.

Well, you should still be able to set some kind of flag there too. Maybe
some flag in a Global scope.

It's the same thing with having Textbox_Change event firer on a Form_load
where you have code in the TextBox_Change event, and you only want the code
in the event to executed when the user changes data in the Textbox.

You don't want the Textbox_Change event to firer on the Form_Load and
execute code because you populated default data in the TextBox.Text =
"MM/DD/YYYY", as an example for display purpose, which will make the
Textbox_Change event firer and code executed if you do bypass it during the
Form_Load.

You simply avoid the situation by setting a gbBoolen flag to true to make it
bypass the code in the Event and set it to false at the end of the Form_Load
to make the event execute the code when it's fired due to the user changing
data in the TextBox.

It's the same principles here. You know the conditions as to when this is
happening so set a Global Boolean flag, if you must, to true and bypass
code execution and set it to false when the method is exited.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top