Results 1 to 4 of 4

Thread: very serious problem !!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    156

    Angry

    I wrote this code:

    Private Sub txtName_LostFocus()
    Call CheckTextValidation(txtName)
    End Sub

    Public Function CheckTextValidation(txt As TextBox) As Boolean
    If txt.Text = Empty Then
    Call MsgBox("you should insert data to this field", vbExclamation + vbOKOnly, App.Title)
    CheckTextValidation = False
    txt.SetFocus
    Else
    CheckTextValidation = True
    End If
    End Function

    But ,it doesn't work properly after it display the first
    msgbox and i clicked OK it display the msgbox AGAIN !!!

    PLEASE HELP
    The MORE I get to know,
    I realize that I know NOTHING !

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    This is just a guess, but you are giving focus to the wrong textbox. Look at you code. You call the validation when TxtName losses focus, and then give focus back to txt. If these are two separate textboxes, then this is your problem, because TxtName will always be losing focus.


    Hope this helps.

  3. #3
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    Unhappy Try this

    That's odd... your code works for me... you can use this simplified method which should work also:

    Code:
    Dim CheckTextValidation As Boolean
    
    Private Sub txtName_LostFocus()
    If txtname.Text = Empty Then
        Call MsgBox("you should insert data to this field", vbExclamation + vbOKOnly, App.Title)
        CheckTextValidation = False
        txtname.SetFocus
    Else
        CheckTextValidation = True
    End If
    
    End Sub
    good luck
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Are there two textboxes you use this method on?
    If so, putting pocus back on the first textbox will cause loosing focus for the second, and so on.

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