Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid Input Problem 1

Status
Not open for further replies.

KKZ

Programmer
Jun 27, 2001
25
0
0
US
I have a grid that has a column controlled by a date field. There is a valid event that triggers if the user enters an undesired date. My problem is that if the user enters 00 or any invalid date, i.e. 02-31-2007, the vfp takes control and would not loose the focus, neither it will trigger the valid event. However, if the user presses the 'Save' button on the form, any code that is in the save button is executed first and then the valid event of the date field triggers.

My question is that is there a way to check that the VFP is controlling the field with the invalid input. If I can determine this, then I can stop running the code from 'Save' button and return the focus back to the field. I would highly appreciate a quick reply and thanks in advance.
 
KKZ,

I assume your Save button is on a toolbar (otherwise the control would have to lose focus in order for the Save code to execute).

To find out if the "VFP is controlling the field with the invalid input", you can get an object reference to _SCREEN.ActiveForm.ActiveControl. That will tell you which control has focus while the Save is in operation.

A better solution might be to set the control's StrictDateEntry to 0, and to do your own date validation.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
When you say "VFP is controlling the field with the invalid input" are you referring to the "Invalid Date" window that pops up?

Maybe this thread that suggests setting NOTIFY to OFF will help?

thread184-1296720

Is your "Save" button in a toolbar? Toolbars do not receive focus, so you may have to add some code to your save routine to ensure that the Valid() of the active control is run first. One option is
Code:
_SCREEN.ActiveForm.ActiveControl.SetFocus()

Teresa
 
Thank you Mike. Your second solution makes more sense. I just have to do a little more to validate date.
 
Teresa!

You guessed right, but set notify is off and no message is displayed. I have a 'Save' button on the form. When I click on it and currently the date field in the grid is in 'VFP control state', neither valid nor lost focus is triggered at that time. It triggers after the save button is done whatever it has to do. That's why I wanted to know if there is way that tells me that VFP is controlling a field with the invalid input. Here is a little what I found during my testing that might help someone else too.

The ControlSource of the field (in my case a date field of a view) shows the original date value, but the column's text field shows empty date. So in the save button I can compare the two values. If they are same, then no problem, otherwise, I can send the control back to that field.

Mike's suggestion about StrictDate is good, but I would need a lot of validation. I think I am to a point where I can control the situation, but this is not a generic solution.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top