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!

Validation Event not fired when using menu or hotkey???

Status
Not open for further replies.

dataent

Programmer
Jun 19, 2001
29
0
0
US
We have just converted over to VB6 and started using the Validation Event. It does not seem that when a menu item is selected the validation event is fired off.

If the user enters information in a text box and clicks on the cmdSave button, the validation event fires, If the user selects save from the menu or hits "F9" which is a hotkey set up for mnuSave, the Validate Event is not fired.

Am I missing something? There is no CausesValidation property on the menus that I can find.

Jeff
 

This is a correct operation. Imagine that validation even being fired on the menus, and everwher else - how would you exit the program?

[/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!
 
Is there any way to trap if one of the hotkeys has been pressed to run the validation event?
 
Your HotKey just runs the normal menu_click event, so to validate Text1 use
Code:
Private Sub mnu1_Click()
Call Text1_Validate(False)
End Sub
Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
On some of my forms, I have as many as 20 different fields that need to validated. One of the menu items is to mnuSave (F9). If the text box they are leaving needs to be validated prior to saving, I can catch it if they click on the cmdSave button but not if they select the menu or press F9. Is there a way to determine they pressed F9 or clicked on the menu before firing the validation event? I do not know which text box they are coming from by the time they hit the mnuSave_Click()
 
Presumably if they hit F9 then all textboxes need to validated, not just the one they left, in case they save before getting to all the textboxes.

If that is the case, you may have to rethink using textbox validation.

Otherwise make all your textboxes an array, and loop through them in the F9 click event Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
um, one way is to putt all textbox validation into a single proceedure(function), (passing an index or whatever), which returns a boolean if the validation passed or not.
This function is called from the normal TextBoxValidation event, and if returns False, it cancels out:

Cancel = Not myValidationFunction()

Or bProceed = myValidationFunction()
If Not bProceed Then
Cancel = True
TextBox.SetFocus
End IF

Then, when clicking an icon to move to a new record, save a record, or what ever, I pop up a msg box asking the user if they want to save, and if so, then call the validation function, and if that returns False, cancel the action.

There are several ways of handling this though..... [/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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top