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!

Function key and control validate 3

Status
Not open for further replies.

SharonLove

Programmer
Feb 26, 2003
18
0
0
DE
Hi,
I have many controls (mostly textboxes) on a form which get their data from a recordset.

The user enters or changes data in the text boxes and either clicks a save button or users a certain function key to save the changes.

The button works fine, but with the function key, the last control that the cursor is on does not run through the validate method.
The lost focus doesn't work for this either.

calling: Text1_Validate(Cancel As Boolean) doesn't work because I do not know which control needs to be called.

What is the generally accepted method used for a situation like this, as it is obvious that there are many possible solutions.

Sharon
 
U need to be more details with your question
thank you.
 
when you do the keypress bit for your function key, can u not move the focus of the textbox onto the save button (this may or may not allow the validate of the text box) then execute the save code?!? clutching at straws a little i know!!

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
 

>clutching at straws a little i know

ADoozer:
Your suggestion would work...but there is a much easier, cleaner method...

Don't forget, a toolbar click will also not cause validation. [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
> but there is a much easier, cleaner method.

CClint:

which is??

(i can think of several ways to go around the problem but, the mybutton.setfocus seems the easiest to me.)

sharon: sorry to gatecrash your thread! If somethings hard to do, its not worth doing - Homer Simpson
 
Sharon ..
You say "The button works fine, but with the function key, the last control that the cursor is on does not run through the validate method.
The lost focus doesn't work for this either."
The reason for this is ... the control still is the active control and has not lost focus, so neither of these events will run. If I remember correctly, the sequence is Validate then Lost focus.
Data validation prior to saving it to the DBase is mandatory and also tricky. Adding an entire new customer is different than changing their address or phone# only and validation needs to be done in very different manners.
However, with what you provided in the question, I would capture the Function keypress at the form level, test the active control and validate it then call the Command button Click event from it.
HTH some
Michael
 
Perhaps if the first step of the Function key is to change the focus to the Save button, the _Validate and _LostFocus events of the control the user was in will be triggered. Then go ahead and call the Save_Click event.
 
Just put the following into the save proceedure:

Const ERR_VALIDATIONCANCELED% = 380

On Error Resume Next
Me.ValidateControls
If Err.Number = ERR_VALIDATIONCANCELED Then 'the validate event of the active control was cancelled
Err.Clear
Exit Sub
End If


This is the only sure method, unless you develop a method of your own to loop through all the controls which need validation.

Actually, this method was developed to be used with the LostFocus event, for those who want the Validation event to kick in even when the next control receiving focus doesn't have the CauseValidation property set to true, or the user has clicked a toolbar or main menu item.

The error is deliberate, or, let's say unavoidable. You could say it is similar to the cancel method of the common dialog. The user, or code cancels an event, and the calling method throws an error back.

Have fun! [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Well I thank you very very much. That (ValidateControls)seems to work just fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top