tags:

views:

18

answers:

1

How do I disable a textbox the second time? here is my code, In form load the textbox is disabled, unless the user will input an idnumber that is in the database. But what if the user will input an idnumber that is in the database then, input again another that is not, That is where this code comes in, but it has problems, it doesnt disable the textbox in the event of a mouse click, what would be the proper way of doing this?

Private Sub Button12_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button12.MouseClick
        Dim NoAcc As String
        Dim NoAccmod2 As String
        Dim NoPas As String

        Dim sqlcon As New MySqlConnection("Server=localhost; Database=school;Uid=root;Pwd=nitoryolai123$%^;")
        Dim sqlcom As MySqlCommand = New MySqlCommand("Select * from student where IDNO= '" & TextBox14.Text & "' ", sqlcon)

        sqlcon.Open()

        Dim rdr As MySqlDataReader
        rdr = sqlcom.ExecuteReader

        If rdr.HasRows Then
            rdr.Read()
            NoAcc = rdr("IDNO")
            If (TextBox14.Text <> NoAcc) Then
                MsgBox("ID Number is not yet registered!, please register first in the general information before trying to register parents information", MsgBoxStyle.Information)
                TextBox7.Enabled = False
                TextBox8.Enabled = False
                TextBox9.Enabled = False
                TextBox10.Enabled = False
                TextBox11.Enabled = False
                TextBox12.Enabled = False
                TextBox13.Enabled = False
            End If
        End If
+1  A: 

At the top of the routine ALWAYS disable the textboxes, then ENABLE them if ID NUMBER matches...

Depending upon what you're actually trying to achieve here, also in the mouse-click you may want to clear the textbox of interest if the ID matches or set it to FOCUS if it does not (to allow them to see what they entered and make changes ... maybe they just mistyped?)

tobrien