Hi,

I needed some help on how to add Validation on text boxes. I wanted validation such as only adding numbers, or max 7 characters for postcode, etc.

I wanted a validation on postcode so that if the correct format doesn't appear (ex, LE5 7LD) then a message box would come up saying format incorrect or something.

I also needed help on making sure a text box is not left blank, and if it is, a error comes up when "Submit" is clicked?

I've tried googline, but couldnt find nothing similar.

Thanks.

this is all of my coding:

Public Class frmcustomer

    Dim MaxRows As Integer
    Dim inc As Integer
    'Define connection variables here
    Dim con As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String
    Private Sub form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = E:\Unit 14\Task B\MyData\SuperTronicsWorld.mdb"
        con.Open()

        sql = "SELECT * FROM tblCustomer"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "SuperTronicsWorld")

        con.Close()

        txtcustid.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(0)
        cbotitle.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(1)
        txtfirstname.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(2)
        txtsurname.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(3)
        txtcompanyname.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(4)
        txtfirstlineadd.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(5)
        txtsecondlineadd.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(6)
        txtcity.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(7)
        txtpostcode.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(8)
        txtcountry.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(9)
        txttelno.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(10)
        lstbank.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(11)
        txtaccno.Text = ds.Tables("SuperTronicsWorld").Rows(0).Item(12)
        MaxRows = ds.Tables("SuperTronicsWorld").Rows.Count
        inc = 0
    End Sub
    Private Sub Navigaterecords()

        txtcustid.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(0)
        cbotitle.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(1)
        txtfirstname.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(2)
        txtsurname.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(3)
        txtcompanyname.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(4)
        txtfirstlineadd.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(5)
        txtsecondlineadd.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(6)
        txtcity.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(7)
        txtpostcode.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(8)
        txtcountry.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(9)
        txttelno.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(10)
        lstbank.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(11)
        txtaccno.Text = ds.Tables("SuperTronicsWorld").Rows(inc).Item(12)

    End Sub

    Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfirst.Click
        If inc <> 0 Then
            inc = 0
            Navigaterecords()

        End If
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        If inc <> MaxRows - 1 Then
            inc = MaxRows - 1
            Navigaterecords()
        End If
    End Sub

    Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click
        If inc > 0 Then
            inc = inc - 1
            Navigaterecords()
        ElseIf inc = -1 Then
            MsgBox("No Records Yet")
        ElseIf inc = 0 Then
            MsgBox("First Record")

        End If
    End Sub

    Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
        If inc <> MaxRows - 1 Then
            inc = inc + 1
            Navigaterecords()

        Else
            MsgBox("No more rows")

        End If
    End Sub

    Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)

        ds.Tables("SuperTronicsWorld").Rows(inc).Item(0) = txtcustid.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(1) = cbotitle.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(2) = txtfirstname.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(3) = txtsurname.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(4) = txtcompanyname.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(5) = txtfirstlineadd.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(6) = txtsecondlineadd.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(7) = txtcity.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(8) = txtpostcode.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(9) = txtcountry.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(10) = txttelno.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(11) = lstbank.Text
        ds.Tables("SuperTronicsWorld").Rows(inc).Item(12) = txtaccno.Text

        da.Update(ds, "SuperTronicsWorld")

        MsgBox("Data Updated")

    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        'enabling/disabling buttons
        btnsave.Enabled() = True
        btnadd.Enabled = False
        btnedit.Enabled = False
        btndelete.Enabled = False
        'clearing the fields
        txtcustid.Clear()
        'cbotitle.clear()
        txtfirstname.Clear()
        txtsurname.Clear()
        txtcompanyname.Clear()
        txtfirstlineadd.Clear()
        txtsecondlineadd.Clear()
        txtcity.Clear()
        txtpostcode.Clear()
        txtcountry.Clear()
        txttelno.Clear()
        'lstbank.clear()
        txtaccno.Clear()



    End Sub

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        If inc <> -1 Then
            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsnewrow As DataRow
            ' InputBox("Please Enter your password to continue to save this record", "Confirmation", "Enter Your Password Here")



            dsnewrow = ds.Tables("SuperTronicsWorld").NewRow()
            dsnewrow.Item("CustomerID") = txtcustid.Text
            dsnewrow.Item("Title") = cbotitle.Text
            dsnewrow.Item("FirstName") = txtfirstname.Text
            dsnewrow.Item("LastName") = txtsurname.Text
            dsnewrow.Item("CompanyName") = txtcompanyname.Text
            dsnewrow.Item("Firstlineaddress") = txtfirstlineadd.Text
            dsnewrow.Item("Secondlineaddress") = txtsecondlineadd.Text
            dsnewrow.Item("City") = txtcity.Text
            dsnewrow.Item("PostCode") = txtpostcode.Text
            dsnewrow.Item("Country") = txtcountry.Text
            dsnewrow.Item("TelNo") = txttelno.Text
            dsnewrow.Item("Banknane") = lstbank.Text
            dsnewrow.Item("Accountnumber") = txtaccno.Text
            ds.Tables("SuperTronicsWorld").Rows.Add(dsnewrow)

            da.Update(ds, "SuperTronicsWorld")
            MsgBox("New Record Successfully appended to the Database!")
            btnsave.Enabled() = False
            btnadd.Enabled = True
            btnedit.Enabled = True
            btndelete.Enabled = True
        End If
    End Sub

    Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        'message to promt for deletion first
        If MessageBox.Show("Are you sure you want to delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
            MsgBox("Operation Cancelled")

            Exit Sub
        End If

        ds.Tables("SuperTronicsWorld").Rows(inc).Delete()
        MaxRows = MaxRows - 1
        inc = 0
        da.Update(ds, "SuperTronicsWorld")
        Navigaterecords()
        btnsave.Enabled() = False
        btnadd.Enabled = True
        btnedit.Enabled = True
        btndelete.Enabled = True


    End Sub

    Private Sub txtfirstname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtfirstname.TextChanged

    End Sub

    Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub

    Private Sub txtpostcode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpostcode.TextChanged

    End Sub
End Class
This article has been dead for over six months. Start a new discussion instead.