Results 1 to 3 of 3

Thread: got focus triggered unnecessarily & validate not getting triggered

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    17

    Post

    my objective is to change the textbox backcolor to green, if empty.


    'please execute & find the answer:-
    'it has 1 command button cmdadd tabindex 3)
    ' 3 text boxes - txtcandid(ti 0),
    ' txtappliedfor(ti 1),
    ' txtindustryid(ti 2)
    'another command button cmdindustryhelp(tabstop false) next to industryid.
    '
    ' form looks like this:-
    '--------------------------------------------
    '| |
    '| txtCandid
    '| txtappliedfor
    '| txtindustryid cmdindustryhelp
    '|
    '| cmdadd
    '--------------------------------------------

    Private Sub cmdAdd_Click()
    txtAppliedfor.SetFocus
    End Sub

    Private Sub cmdIndustryIdHelp_Click()
    MsgBox "hello"
    txtIndustryId.SetFocus
    End Sub

    Private Sub Form_Load()
    txtCandId.Enabled = False
    End Sub

    Private Sub txtAppliedfor_GotFocus()
    txtAppliedfor.BackColor = vbWhite
    End Sub

    Private Sub txtAppliedfor_Validate(Cancel As Boolean)
    If txtAppliedfor.Text = "" Then
    txtAppliedfor.BackColor = vbGreen
    End If
    End Sub


    can u help?

    friendly,
    jey.

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124

    Post

    The code that you have worked fine for me. You may have spaces in your textboxes and just don't realize it. Try using the Trim() function like this:
    Code:
    Private Sub txtAppliedfor_Validate(Cancel As Boolean)
        If Trim(txtAppliedfor.Text) = "" Then
            txtAppliedfor.BackColor = vbGreen
        End If
    End Sub

  3. #3
    New Member
    Join Date
    Jan 2000
    Location
    Chennai
    Posts
    4

    Post

    Hi Jeyashree,
    How are you.... Here come the solution for your query....
    ''''''''''''''''''''''''''''''''''''''''''''
    ' No of TextBox's - 3 ( control array)
    ''''''''''''''''''''''''''''''''''''''''''''
    ' IfVirus(0)
    ' IfVirus(1)
    ' IfVirus(2)
    ''''''''''''''''''''''''''''''''''''''''''''
    ' No of Command Buttons - 2
    ''''''''''''''''''''''''''''''''''''''''''''
    ' cmdAdd
    ' cmdIndustryIdHelp
    ''''''''''''''''''''''''''''''''''''''''''''

    Private Sub cmdAdd_Click()
    IfVirus(1).SetFocus
    End Sub

    Private Sub cmdIndustryIdHelp_Click()
    IfVirus(2).SetFocus
    End Sub

    Private Sub Form_Load()

    For i = 0 To IfVirus.Count - 1

    If Len(Trim(IfVirus(i))) = 0 Then
    IfVirus(i).BackColor = vbGreen
    Else
    IfVirus(i).BackColor = vbWhite
    End If

    Next
    End Sub

    Private Sub IfVirus_Change(Index As Integer)

    If Len(Trim(IfVirus(Index))) = 0 Then
    IfVirus(Index).BackColor = vbGreen
    Else
    IfVirus(Index).BackColor = vbWhite
    End If

    End Sub
    ''''''''''''''''''''''''''''''''''''''''''''

    Yours

    Murali
    [email protected]
    [email protected]

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