Solved

Search function in vb.net using an access db

Posted on 2007-04-10
11
183 Views
Last Modified: 2008-01-09
I would like to be able to have a text box where the user enters a name (which is also the field name) and upon clicking the find button, the form will find that record. A find next button will take you to the next record. I am using vb.net as the front end with Access as the back end. How can I go about doing this.
0
Comment
Question by:carlosm06
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
11 Comments
 
LVL 27

Expert Comment

by:VBRocks
ID: 18885630
A very easy way to do this is create a BindingSource and set it's DataSource to whatever list or source you have, then set the BindingSource the DataSource of a BindingNavigator.

First, Add a BindingNavigator to your form, we can call "bn"
Second, create your BindingSource:
Dim bs As New BindingSource()
bs.DataSource = MyList     'Whatever your list is.
bn.BindingSource = bs

If you have a textbox name "Text1" you can filter your bindingsource as follows:
bs.Filter = "ColumnName='" & Text1.Text & "'"

When you want to remove the filter, do as follows:
bs.RemoveFilter()



0
 
LVL 27

Accepted Solution

by:
VBRocks earned 250 total points
ID: 18885772
Here is a little example I put together:

First, I created a form and added a BindingNavigator, a textbox to display the data (tbMyColumn), a textbox for search criteria (tbSearch)
Second, I created a DataSet in the designer and added 1 table to it called "MyTable" with 1 column named "MyColumn.

    Private bs As New BindingSource()

    Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        Dim ds As New DataSet1()
        Dim row As DataSet1.MyTableRow

        'Load the dataset with data
        For i = 1 To 10
            row = ds.MyTable.NewMyTableRow()
            row.MyColumn = i

            ds.MyTable.AddMyTableRow(row)

        Next

        'Set the datasource of the BindingSource
        bs.DataSource = ds.MyTable

        'Set the BindingSource for the BindingNavigator
        Me.BindingNavigator1.BindingSource = bs

        'Bind the Text property to your column
        Me.tbMyColumn.DataBindings.Add(New Binding("Text", bs, "MyColumn"))

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'This is the button that the user clicks to perform the search
        bs.Sort = "MyColumn ASC"
        bs.Filter = "MyColumn='" & Me.tbSearch.Text & "'"

    End Sub

0
 
LVL 18

Expert Comment

by:Priest04
ID: 18886256
If you dont want to show only filtered records (like I dont), the other way would be to do a loop through all the records and search for criteria in desired column. If you find a match, you remember the position of the record that matches the criteria. If user preses find next button, you ill loop again through records, but starting from a record that matched the criteria.

Goran
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:carlosm06
ID: 18892369
So if I had the textbox on a seperate form how could I call the record on main form.  Right now I have a small form that users can type in a name and click the search button. When the record is found, I would like to bring up another form with the found record. This is the form used to input data...
0
 
LVL 18

Assisted Solution

by:Priest04
Priest04 earned 250 total points
ID: 18894222
1) You show this separate form modally
2) on this separate form have some public variable, to which you will assign value from textbox.
3) When the user clicks search button, close the separate from
4) the code will be returned to main form, so you can read the search value that is stored in a public variable
5) after that, you can use either VBRocks's suggestion, or mine, it all depends what info do you have on this main form, is data shown only for one record, or data are presented in some tabular form (like in datagridview).

Goran
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 19258516
Definitely still interested.  I provided a simple and effective, but detailed example.

0
 

Author Comment

by:carlosm06
ID: 19258626
Where's the example vbrocks?
0
 
LVL 18

Expert Comment

by:Priest04
ID: 19264787
carlosm06, do you find our answers unhelpful?

Goran
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question