|
-
Feb 6th, 2007, 02:50 AM
#1
Thread Starter
Addicted Member
Validate event
Hi,
I'm notice that every control (built in or third party) will have this event create automatically by VB.
This event working greatly. But when i moving focus to other control using code, this event doesn't fire. Is that this control normal behaviour or something wrong?
Thanks
-
Feb 6th, 2007, 02:57 AM
#2
Re: Validate event
Use SendKeys to move to the next control with the Tab button.
Use Text1 TextBox, Timer1 Timer (with for example .Interval set to 3000) and some other control that CAN gain focus for this example:
VB Code:
Option Explicit
Private Sub Text1_Validate(Cancel As Boolean)
MsgBox "Test"
End Sub
Private Sub Timer1_Timer()
SendKeys "{TAB}", True
End Sub
-
Feb 6th, 2007, 03:42 AM
#3
Thread Starter
Addicted Member
Re: Validate event
Sorry gavio, your answer didn't solve my problem
-
Feb 6th, 2007, 04:12 AM
#4
Re: Validate event
Well, it works for me. If you didn't noticed that was only an example (of many) on how to solve your problem. When the Timer triggers (in 3 seconds), it should send the focus to the next control and trigger the Text1_Validate(...) event. That should show the MsgBox...
-
Feb 6th, 2007, 04:51 AM
#5
Thread Starter
Addicted Member
Re: Validate event
Hi,
Sorry gavio, but my question is:
Is that validate event will not fired when we exit control using code?
-
Feb 6th, 2007, 07:27 AM
#6
Re: Validate event
The Validate Event fires before the focus shifts to a (second) control that has its CausesValidation property set to True.
The Validate event works in tandem with the CausesValidation property to prevent a control from losing the focus until certain criteria are met. By default, most if not all, controls have Causesvalidation set to True, so you should not be having a issue with the event firing.
What code do you have in the Validate event that does not seem to be executing? What are the controls involved, and how are you moving from one control to another through code?
-
Feb 6th, 2007, 02:21 PM
#7
Re: Validate event
VB Code:
Private Sub Text1_Validate(Cancel As Boolean)
If Not IsNumeric(Text1.Text) Then
MsgBox "not numeric"
Cancel = True
End If
End Sub
Private Sub Command3_Click()
Text2.SetFocus
End Sub
If the focus is on Text1 and Command3 is clicked, and the text in Text1 isn't numeric, the MsgBox comes up and the focus stays in Text1.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Feb 6th, 2007, 02:32 PM
#8
Hyperactive Member
Re: Validate event
isn't that what you want.
if you want the focus to go to text2 then set cancel = false after your message box
edit: oops sorry AL42 I thought this was your thread lol.
Last edited by ggettings; Feb 6th, 2007 at 08:11 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|