views:

36

answers:

3

I have several textboxes and users are entering same data in one of these fields. I have another table which is store machine_no. I would like to restrict user for possible wrong entries. Example if there is no machine_no #4 on table, user will be warn with message box.

Machine_no      Value1    In first day
1               500
2               400
3               600

Machine_no      Value1    second day
1               8678
2               45645
3               54645

Thanks in advance

+1  A: 

If you really want to restrict the available choices, I'd replace the free form textbox with a dropdown list of choices populated from your table.

Joe Stefanelli
Sorry but this is not answer for me. Because I have more than 1000 records on my table. and I have to restrict users to enter wrong numbers. If I use dropdownlist they have to chose from list. It's too much time loss for data entry.
Hakan
There are scripting techniques to make using the dropdown less painful in these cases. Google "type ahead dropdown" or "autocomplete dropdown" and you'll find some good examples.
Joe Stefanelli
A: 

You could use a NumericUpDown control to let the user enter only integers and validate against a generic List of integers or an array of integers (you can load the list with the existing machine numbers on your data base table), and finally you can use ErrorProvider control to show a warning to the user if enters a not valid number.

Mario
A: 

OK, I am trying with following code but it's not validating. Always gives me check machine no.

I am getting closer but there is some little mistake. I can fin it what.

Dim table As DataTable = Me.DataSet1.Tables.Item("tbl_machines")
        Dim defaultView As DataView = table.DefaultView
        defaultView.RowFilter = (String.Format("local_no='{0}'", Machine_noTextBox.Text))
        If ((Char.IsLetter(CharType.FromString(Machine_noTextBox.Text)) Or (defaultView.Count = 0)) Or (StringType.StrCmp(Machine_noTextBox.Text, "", False) = 0)) Then
            Interaction.MsgBox("Check Machine No", &H40, "Check")
            Machine_noTextBox.Focus()
        Else
            TurnoverTextBox.Focus()
        End If
Hakan