Results 1 to 4 of 4

Thread: LostFocus Event's problems

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    156

    Post

    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

    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
    Dec 1999
    Posts
    321

    Arrow Give the focus back

    You see, you have to give the focus back to the textbox, otherwise vb will just keep running that code.

    use something like
    Code:
    Text1.SetFocus
    and put it after you've showed the msgbox





    [Edited by Rodik on 06-25-2000 at 01:19 AM]
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    156

    Unhappy well,I did it ,but still it doesn't work

    Public Function CheckTextValidation(txt As TextBox) As Boolean
    If txt.Text = Empty Then
    Call MsgBox("xxxxxxxxxxx", vbExclamation + vbOKOnly, App.Title)
    CheckTextValidation = False

    ----> txt.SetFocus <----
    Else
    CheckTextValidation = True
    End If
    End Function
    The MORE I get to know,
    I realize that I know NOTHING !

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Originally posted by lirlir
    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

    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
    If you only need to validate the text inside a textbox control, you actually no need to pass the entire TextBox control into your CheckTextValidation function. All you need is...

    Code:
    Private Sub txtName_LostFocus()
        If  CheckTextValidation (txtName.Text) then
            'Proceed what you need to do
        Else
            'Proceed to do something else...
        End If
    End Sub
    
    Public Function CheckTextValidation(txt As String) As Boolean
    If txt = "" Then
        MsgBox "you should insert data to this field", vbExclamation + vbOKOnly, App.Title
        CheckTextValidation = False
    Else
        CheckTextValidation = True
    End If
    End Function

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