Results 1 to 8 of 8

Thread: Validate event

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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:
    1. Option Explicit
    2.  
    3. Private Sub Text1_Validate(Cancel As Boolean)
    4.     MsgBox "Test"
    5. End Sub
    6.  
    7. Private Sub Timer1_Timer()
    8.     SendKeys "{TAB}", True
    9. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: Validate event

    Sorry gavio, your answer didn't solve my problem

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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...

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: Validate event

    Hi,

    Sorry gavio, but my question is:
    Is that validate event will not fired when we exit control using code?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Validate event

    VB Code:
    1. Private Sub Text1_Validate(Cancel As Boolean)
    2. If Not IsNumeric(Text1.Text) Then
    3.   MsgBox "not numeric"
    4.   Cancel = True
    5. End If
    6. End Sub
    7.  
    8. Private Sub Command3_Click()
    9. Text2.SetFocus
    10. 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

  8. #8
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    376

    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
  •  



Click Here to Expand Forum to Full Width