Results 1 to 5 of 5

Thread: Validate controls MDI Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Question Validate controls MDI Form

    I have a problem with validating my textboxes.

    I have 3 forms: - 1 MDI and 2 MDI Childs

    Textboxes on one of the MDI Childs need to be validated. Everything works fine by using the Validate procedure as long as I stay on that MDI Child.

    VB Code:
    1. Private Sub txtFCS_Validate(Index As Integer, KeepFocus As Boolean)
    2. 'Some code here
    3. KeepFocus = True
    4. MsgBox "Wrong Value"
    5. End Sub
    As soon as I access the menu from the MDI form or I do click on the other MDI Child my textboxes don't get validated anymore.

    Any idea how to fix this?

  2. #2
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    I hope this helps you. I just added a couple of lines of code...

    (Yet I wonder why you have the KeepFocus argument and I only have the Cancel one)

    Here is the code I used:

    VB Code:
    1. Private Sub txtFCS_LostFocus(Index As Integer)
    2.  txtFCS_Validate Index, False
    3. End Sub
    4.  
    5. Private Sub txtFCS_Validate(Index As Integer, Cancel As Boolean)
    6.  'Your condition here instead of "Not IsNumeric(txtFCS(Index))"
    7.  If Not IsNumeric(txtFCS(Index)) Then
    8.   Cancel = True
    9.   MsgBox "Wrong Value"
    10.  
    11.   Me.SetFocus
    12.   txtFCS(Index).SetFocus
    13.  End If
    14. End Sub
    Attached Files Attached Files
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96
    This code works, problem starts occuring as soon as I add a menu item to the form parent.

    If I click an item in the menu, it does not validate the control, it just executes the code under the menu_click event.

    If I add a Label to the empty form, and add a Mousedown event.

    VB Code:
    1. Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Me.Label1.Caption = Me.Label1.Caption + 1
    3. End Sub

    The MouseDown event gets executed before the Validate event from the form which just lost focus.

    Any workaround?

  4. #4
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    You mean something like this?
    Attached Files Attached Files
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  5. #5
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Oops... Sorry, wrong attachment.
    Attached Files Attached Files
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

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