How to create Search form for database.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ali3n8
    New Member
    • Aug 2007
    • 50

    How to create Search form for database.

    Hello I would like to create a search form for my database that searches by:

    First
    Last
    Contact Number
    Street
    City
    State
    Zip

    What is the easiest way possible to accomplish this? I guess I should mention I have a table called tblcustomerinfo rmation. I would like the search to list possible matches and from that list I would like to be able to click and open the record.

    Thank you
  • Stang02GT
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Originally posted by ali3n8
    Hello I would like to create a search form for my database that searches by:

    First
    Last
    Contact Number
    Street
    City
    State
    Zip

    What is the easiest way possible to accomplish this? I guess I should mention I have a table called tblcustomerinfo rmation. Once the search is completed I will like it to open the matching record.

    There are a couple different ways you can do this...

    1.You can have text boxes where the users enter search criteria and then press a "search" button
    2.You can have a combo box preform your search. The user can either type in what they want to search for or select from a list

    I personally like the "search button" method. I am sure others memebers of TSDN will have other ideas but if you would like to do this let me know and I can help you out.


    Have a good one!

    Comment

    • ali3n8
      New Member
      • Aug 2007
      • 50

      #3
      Originally posted by Stang02GT
      There are a couple different ways you can do this...

      1.You can have text boxes where the users enter search criteria and then press a "search" button
      2.You can have a combo box preform your search. The user can either type in what they want to search for or select from a list

      I personally like the "search button" method. I am sure others memebers of TSDN will have other ideas but if you would like to do this let me know and I can help you out.


      Have a good one!

      Search Button is exactly what im looking for.

      Comment

      • Stang02GT
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Originally posted by ali3n8
        Search Button is exactly what im looking for.

        Ok well here is what you are going to need to do

        Once you are have your form created with all the feilds you would like displayed, you are going to create a BOUND text box. (Bound means that it is connected with a feild in a table) in this example i will use LastName.

        1.Once you have created your bound text box ( i can tell you how to do this if you don't know). You will wnat to create a blank button next to it.
        2. Once you have created the button place this code in the "OnClick" event of the button. You are going to have to put the appropreate names in the corrisponding places

        Code:
        Private Sub ButtonsName_Click()
           If IsNull(TextboxesName) = False Then
              Me.Recordset.FindFirst '[FeildYourSearchingFor]=' & TextboxesName
              Me!TextboxesName = Null
              If Me.Recordset.NoMatch Then
                 MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
                    Me!TextboxesName = Null
              End If
           End If
        End Sub
        This code will search, and if there is no result it will pop up a message telling the user there was not record found, and it will clear the txt box after the search is completed.
        Last edited by Frinavale; Feb 11 '11, 09:33 PM. Reason: Added code tags.

        Comment

        • ali3n8
          New Member
          • Aug 2007
          • 50

          #5
          Originally posted by Stang02GT
          Ok well here is what you are going to need to do

          Once you are have your form created with all the feilds you would like displayed, you are going to create a BOUND text box. (Bound means that it is connected with a feild in a table) in this example i will use LastName.

          1.Once you have created your bound text box ( i can tell you how to do this if you don't know). You will wnat to create a blank button next to it.
          2. Once you have created the button place this code in the "OnClick" event of the button. You are going to have to put the appropreate names in the corrisponding places

          Code:
          Private Sub ButtonsName_Click()
             If IsNull(TextboxesName) = False Then
                Me.Recordset.FindFirst '[FeildYourSearchingFor]=' & TextboxesName
                Me!TextboxesName = Null
                If Me.Recordset.NoMatch Then
                   MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
                      Me!TextboxesName = Null
                End If
             End If
          End Sub
          This code will search, and if there is no result it will pop up a message telling the user there was not record found, and it will clear the txt box after the searc is completed.
          Do I need to create a new table or can I just create a new form and label the text boxes on that?
          Last edited by Frinavale; Feb 11 '11, 09:33 PM.

          Comment

          • ali3n8
            New Member
            • Aug 2007
            • 50

            #6
            How do I create a bound text box. I created a new text box on a form and it says unbound.

            Comment

            • Stang02GT
              Recognized Expert Top Contributor
              • Jun 2007
              • 1206

              #7
              To create a bound text box you are going to need to....

              1. Right Click on the text box
              2. Select Properties
              3.Click on the Data tab
              4. There should be a drop down with selections of the feilds in your table(if your form is bound to a table)

              To bind a form to a table
              1. In the properties menu for the Form do to the data tab
              2.Click the drop down box and select the table you would like the form bound to

              Comment

              • Stang02GT
                Recognized Expert Top Contributor
                • Jun 2007
                • 1206

                #8
                If im not explaing things good enough here are a couple sites you can take a look at there are very good and provide a lot of detailed information about how to do things in Access

                Search Form

                How To Articles

                More How To's

                Comment

                • ali3n8
                  New Member
                  • Aug 2007
                  • 50

                  #9
                  I created a form and dragged the fields I wanted to the form. I create the command button and also pasted what you gave me on clickevent. I get errors when I click the button.

                  MS Access can't find the macro 'private Sub ButtonsName_Cli ck() if IsNull(Contact Number)= False Then Me.

                  Comment

                  • Stang02GT
                    Recognized Expert Top Contributor
                    • Jun 2007
                    • 1206

                    #10
                    Originally posted by ali3n8
                    I created a form and dragged the fields I wanted to the form. I create the command button and also pasted what you gave me on clickevent. I get errors when I click the button.

                    MS Access can't find the macro 'private Sub ButtonsName_Cli ck() if IsNull(Contact Number)= False Then Me.
                    Did you name the button "ButtonsNam e"?

                    Access names it by default something like" Command_15"

                    Comment

                    • ali3n8
                      New Member
                      • Aug 2007
                      • 50

                      #11
                      To name the button, In design view I right click on the button and then select the all tabe. There is a field there called name in the field I inputed "ButtonsNam e". Is that correct?

                      Comment

                      • Stang02GT
                        Recognized Expert Top Contributor
                        • Jun 2007
                        • 1206

                        #12
                        Yes, but you can name the button whatever you'd like. Just make sure that whatever you name it to you change it in the code, because if you don't then Access doens't know where to look when you press the button

                        Comment

                        • ali3n8
                          New Member
                          • Aug 2007
                          • 50

                          #13
                          Can you highlight for me what areas in this code i need to edit I may have edited it incorrectly. Here is what I did below:
                          Code:
                          Private Sub ButtonsName_Click()
                             If IsNull(Contact Number) = False Then
                                Me.Recordset.FindFirst '[Contact Number]=' & Contact Number
                                Me!Contact Number = Null
                                If Me.Recordset.NoMatch Then
                                   MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
                                      Me!Contact Number = Null
                                End If
                             End If
                          End Sub
                          Last edited by Frinavale; Feb 11 '11, 09:34 PM. Reason: Added code tags

                          Comment

                          • Stang02GT
                            Recognized Expert Top Contributor
                            • Jun 2007
                            • 1206

                            #14
                            Code:
                            Private Sub ButtonsName_Click()
                               If IsNull([B]Contact Number[/B]) = False Then
                                  Me.Recordset.FindFirst '[Contact Number]=' & [B]Contact Number[/B]
                                  Me!Contact Number = Null
                                  If Me.Recordset.NoMatch Then
                                     MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
                                        Me![B]Contact Number [/B] = Null
                                  End If
                               End If
                            Change the bolded names to something different, and make sure you don't put spaces.

                            Try something like ContactNum

                            Comment

                            • ali3n8
                              New Member
                              • Aug 2007
                              • 50

                              #15
                              Originally posted by Stang02GT
                              Code:
                              Private Sub ButtonsName_Click()
                                 If IsNull([B]Contact Number[/B]) = False Then
                                    Me.Recordset.FindFirst '[Contact Number]=' & [B]Contact Number[/B]
                                    Me!Contact Number = Null
                                    If Me.Recordset.NoMatch Then
                                       MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
                                          Me![B]Contact Number [/B] = Null
                                    End If
                                 End If
                              Change the bolded names to something different, and make sure you don't put spaces.

                              Try something like ContactNum

                              They bolding did not appear on your post.

                              Comment

                              Working...