2 Replies - 462 Views - Last Post: 08 May 2012 - 03:32 AM Rate Topic: -----

#1 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 161
  • Joined: 04-November 10

giving focus to another textbox

Posted 08 May 2012 - 02:47 AM

I am entering a values into another textbox and I want it to surrender Focus to another textbox if the value I have entered is the same as the one in the database.However what is happening is that if the value is the same as in the database the cursor just disappears and it does not give focus to the control that I want it to give focus to. Any ideas on how I can correct this.

 Private Sub txtProducedAt_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtProducedAt.TextChanged

        Dim iSql As String = "SELECT ID,SiteName   FROM  Sites WHERE SiteName = '" & txtProducedAt.Text & "'     "
        Dim da As New OleDbDataAdapter(iSql, LoginForm1.Conn)
        Dim dTable As DataTable = New DataTable
        da.Fill(dTable)
        If dTable.Rows.Count = 0 Then

            Exit Sub

        ElseIf dTable.Rows.Count > 0 Then

            txtProducedAt.Text = dTable.Rows(0)("SiteName").ToString

            txtAccountNumber.Select()

        End If

    End Sub



I've tried putting code into the tabindex changed event but its not doing what i want and also in the lostfocus event
Private Sub txtProducedAt_TabIndexChanged(sender As Object, e As System.EventArgs) Handles txtProducedAt.TabIndexChanged

        Dim iSql As String = "SELECT ID,SiteName   FROM  Sites WHERE SiteName = '" & txtProducedAt.Text & "'     "
        Dim da As New OleDbDataAdapter(iSql, LoginForm1.Conn)
        Dim dTable As DataTable = New DataTable
        da.Fill(dTable)
        If dTable.Rows.Count = 0 Then

            Exit Sub

        ElseIf dTable.Rows.Count > 0 Then

            txtAccountNumber.Focus()

        End If
    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: giving focus to another textbox

#2 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 93
  • View blog
  • Posts: 871
  • Joined: 15-October 10

Re: giving focus to another textbox

Posted 08 May 2012 - 03:11 AM

You could try:(although this is not tested)

If txtProducedAt.Text = dTable.Rows(0)("SiteName").ToString  Then
txtAccountNumber.Focus()  
End IF




Was This Post Helpful? 1
  • +
  • -

#3 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 161
  • Joined: 04-November 10

Re: giving focus to another textbox

Posted 08 May 2012 - 03:32 AM

THANKS SO MUCH THE CODE WORKS WELL
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1