Search function in using an access db

Posted on 2007-04-10
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 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



        '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.

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

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 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).

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

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.…

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