0

Hi, Im trying to input a search box in my forms so that when I type in a customers name it will show there record. I've managed to do it in my transaction form, but not in any other standard forms. In my transaction form I've got this code:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSearchSalesID.KeyPress
        Dim dv As DataView = New DataView()
        dv.Table = SuperTronicsWorldDataSet1.tblSales
        dv.RowFilter = "SalesID = '" & txtSearchSalesID.Text & "'"
        TblSalesBindingSource.DataSource = dv

      
    End Sub

I want to put a search box in my customer form...This is the whole code in my customer form so far:

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
        'Locates the connection
        con.ConnectionString = My.Settings.SuperTronicsWorldConnectionString
        con.Open()
        'Selects the table and locates the information from their
        sql = "SELECT * FROM tblCustomer"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "SuperTronicsWorld")

        con.Close()
        'Tells the application which row and column the information is located at
        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()
        'Allows the program to navigate the records
        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
        'Takes the user to the last record
        If inc <> MaxRows - 1 Then
            inc = MaxRows - 1
            Navigaterecords()
        End If
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click

        'Takes the user back to the first record
        If inc <> 0 Then
            inc = 0
            Navigaterecords()

        End If
    End Sub

    Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click
        'Takes the user to the previous record
        If inc > 0 Then
            inc = inc - 1
            Navigaterecords()
            'If the user reaches the last record then it will show a message box
        ElseIf inc = -1 Then
            MsgBox("No Records Yet")
            'If the user reaches the first record then it will show a message box if they try to carry on going back
        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
        'Takes the user to the next record
        If inc <> MaxRows - 1 Then
            inc = inc + 1
            Navigaterecords()
            'If there are no more records and the user reaches the end then a message box will show up
        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)
        'Tells the application to update all the records and where they are located
        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")
        'Shows a message box once the process of updating is complete
        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.ResetText()
        txtfirstname.Clear()
        txtsurname.Clear()
        txtcompanyname.Clear()
        txtfirstlineadd.Clear()
        txtsecondlineadd.Clear()
        txtcity.Clear()
        txtpostcode.Clear()
        txtcountry.Clear()
        txttelno.Clear()
        lstbank.ClearSelected()
        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


            'Telling the application which heading to save the contents in each of the textbox under

            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("Bankname") = lstbank.Text
            dsnewrow.Item("Accountnumber") = txtaccno.Text
            ds.Tables("SuperTronicsWorld").Rows.Add(dsnewrow)
            'The database name
            da.Update(ds, "SuperTronicsWorld")
            'Shows a message box once the details have been saved
            MsgBox("New Record Successfully appended to the Database!")
            'Disables the Save button so that it cannot be reclicked
            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
        'Deletes the record/row that the user is on at that time
        ds.Tables("SuperTronicsWorld").Rows(inc).Delete()
        MaxRows = MaxRows - 1
        inc = 0
        da.Update(ds, "SuperTronicsWorld")
        Navigaterecords()
        'Diables the save button as there is no need for it
        btnsave.Enabled() = False
        btnadd.Enabled = True
        btnedit.Enabled = True
        btndelete.Enabled = True


    End Sub

    Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
        'Closes the form
        Me.Close()

    End Sub

    Private Sub txtfirstname_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtfirstname.Leave
        'Makes sure the first name text box is not left empty, if it is, then a message box is shown and the cursor is re-focused on the text box.
        If txtfirstname.Text = "" Then
            MsgBox("Please Enter the First Name")
            txtfirstname.Focus()

        End If
    End Sub


    Private Sub txtcustid_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcustid.Leave
        'Makes sure the first name text box is not left empty, if it is, then a message box is shown and the cursor is re-focused on the text box.
        If txtcustid.Text = "" Then
            MsgBox("You must enter a Customer ID")
            txtcustid.Focus()
        End If
       
       
    End Sub

   

    Private Sub txtsurname_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsurname.Leave
        'Makes sure the Surname text box is not left empty, if it is, then a message box is shown and the cursor is re-focused on the text box.
        If txtsurname.Text = "" Then
            MsgBox("Please Enter the Surname")
            txtsurname.Focus()
        End If
    End Sub


    Private Sub txtfirstlineadd_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtfirstlineadd.Leave
        'Makes sure the first line address text box is not left empty, if it is, then a message box is shown and the cursor is re-focused on the text box.
        If txtfirstlineadd.Text = "" Then
            MsgBox("Please Enter the First Line of Address")
            txtfirstlineadd.Focus()
        End If
    End Sub
    Private Sub txtcity_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcity.Leave
        'Makes sure the City text box is not left empty, if it is, then a message box is shown and the cursor is re-focused on the text box.
        If txtcity.Text = "" Then
            MsgBox("Please Enter the City")
            txtcity.Focus()
        End If
    End Sub

    Private Sub txtpostcode_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpostcode.Leave
        'Makes sure the Postcode text box is not left empty, if it is, then a message box is shown and the cursor is re-focused on the text box.
        If txtpostcode.Text = "" Then
            MsgBox("Please Enter the Post Code")
            txtpostcode.Focus()
        End If
        
    End Sub

    Private Sub txtcountry_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcountry.Leave
        'Makes sure the Country text box is not left empty, if it is, then a message box is shown and the cursor is re-focused on the text box.
        If txtcountry.Text = "" Then
            MsgBox("Please Enter the Country Name")
            txtcountry.Focus()
        End If
    End Sub

    Private Sub txttelno_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttelno.Leave
        'Makes sure the Tel no text box is not left empty, if it is, then a message box is shown and the cursor is re-focused on the text box.
        If txttelno.Text = "" Then
            MsgBox("Please Enter a Telephone Number")
            txttelno.Focus()
        End If
    End Sub
    Private Sub txtaccno_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtaccno.Leave
        'Makes sure the Account Number text box is not left empty, if it is, then a message box is shown and the cursor is re-focused on the text box.
        If txtaccno.Text = "" Then
            MsgBox("Please Enter the Account Number")
            txtaccno.Focus()
        End If
     
        
      
    End Sub

  
    Private Sub txtcustid_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcustid.TextChanged
        'This code only allows the maximum length of 3 characteres entered into this text box
        txtcustid.MaxLength = 3

    End Sub

    

   

    Private Sub cbotitle_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbotitle.LostFocus
        'this a select case coding which ensure the user select one of the following options
        If (cbotitle.Text = "Mr") Or (cbotitle.Text = "Mrs") Or (cbotitle.Text = "Miss") Or (cbotitle.Text = "Dr") Then
            Select Case cbotitle.Text
                Case cbotitle.Text = "Mr"
                Case cbotitle.Text = "Mrs"
                Case cbotitle.Text = "Miss"
                Case cbotitle.Text = "Dr"
            End Select
        Else
            cbotitle.Text = ""
            MsgBox("Please select the following Title from the Combo box")
            cbotitle.Focus()
            cbotitle.Text = "Mr"
        End If
    End Sub

End Class

I cant use the same code, because there isn't any datasets...And im not sure how to refer it back to my database now.

Can someone please help me?

Thanks.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by pritesh2010
0

hii your code is right but what do you want from this. that i can't understand . if you want to use the same code in your two three form then create one class module and pass the vale at their and retrieve by creating a object.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.