Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Search function in using an access db

Posted on 2007-04-10
Medium Priority
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 as the front end with Access as the back end. How can I go about doing this.
Question by:carlosm06
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
LVL 27

Expert Comment

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:

LVL 27

Accepted Solution

VBRocks earned 1000 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



        '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

LVL 18

Expert Comment

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.

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

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...
LVL 18

Assisted Solution

Priest04 earned 1000 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).

LVL 27

Expert Comment

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


Author Comment

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

Expert Comment

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


Featured Post

Technology Partners: 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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

664 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