I need a VBA code for my unbound Search form.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aswgawlag
    New Member
    • Nov 2011
    • 16

    I need a VBA code for my unbound Search form.

    Hi,

    I have a search form, which is now unbound from my table, and by that I mean I have gone and set the form's Record Source to remain blank. I have also gone and set the Control Source of each text box and combo box to also remain blank.

    I did this because when I would search for a record by a particular field, by Document Number for example, the data I typed into the text box, or selected in the combo box, would then be stored as a new record in my table, which I did not want.

    So, by doing this my Search button no longer works.

    Now, do I need to write a VBA code consisting of information that will let me search by each field? For instance, in my code do I need to include information that will let me search by the Document Number, and/or File Type, and/or Revision, and/or Project, and/or Manufacturer, and so forth?

    I have been searching all day for example VBA codes for searching, but have not been successful.

    Thank you for any input.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32634

    #2
    Your first steps are certainly correct ones.

    Check out these articles for what is hopefully, all you need on the subject :
    Example Filtering on a Form.
    Cascaded Form Filtering.

    NB. Although filtering is often associated with searching, the two terms are not exactly synonymous. Searching selects a record from within a larger group (recordset), whereas filtering restricts the group to include only those records which match the criteria. From the titles you'll see that both articles pertain directly to filtering, but it's not too much of a stretch from there to use the same concept as a search instead.

    When you've been through the articles come back if you feel you need help with converting them to be specifically search related.

    Comment

    • aswgawlag
      New Member
      • Nov 2011
      • 16

      #3
      NeoPa,

      Thank you. I have rethought my design and think the use of a filter would indeed be better. I would like for users to be able to search for only those records in which they specify based upon one or more fields. For instance, a user may want to search for only those records that are ".docx" files and "approved." Then, those records that meet the two criteria, for example, would populate a read-only table. My form is set to read-only, so I may not have to do anything there since I was thinking I would just change my single form to a split form and then the search results would populate the table on the same form. I have tried this, although the filter button I set up using the Command Button Wizard is not working.

      At first it stated the records were locked, which they were, so I set that property to "No Records," but still no luck.

      I used the filter by form tool on my table itself and do like how it works. At this point, I am not sure what needs to be done. Do I need to set up a filter on the table itself for the filter records button to work on my form? Or do I just need to write a code for the button to work on my form?

      Any feedback is greatly appreciated.

      Thank you.

      Comment

      • Mihail
        Contributor
        • Apr 2011
        • 759

        #4
        Take a look here:


        The thread is not finalized but maybe you can find anything useful.

        Comment

        • aswgawlag
          New Member
          • Nov 2011
          • 16

          #5
          Mihail,

          I can't open the link for some reason. It keeps closing the program.

          Thank you.

          Comment

          • aswgawlag
            New Member
            • Nov 2011
            • 16

            #6
            O.k. I did change my Default View in the Properties Pane to a Split Form. I also changed the Split Form Datasheet to Read-only in the Properties Pane as well. When I select the criteria (combo boxes) or type in the criteria (text boxes)for the fields I wish to filter by though, nothing happens.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32634

              #7
              I'm somewhat confused as you're talking about populating a read-only table at one point. This is strange because :
              1. Read-only tables cannot be populated under any circumstances.
              2. Forms don't generally populate tables as such. They are able to maintain records in a table (and even add new ones), but populating a table is a term I would associate more with an APPEND query.


              Originally posted by Aswgawlag
              Aswgawlag:
              Do I need to set up a filter on the table itself for the filter records button to work on my form? Or do I just need to write a code for the button to work on my form?
              You certainly don't need to change the design of the table at all. The form only is changed, and that is temporary as this isn't saved into the design of the form.

              Your questions seem to indicate that you haven't looked at, or maybe just understood very well, either of the articles I linked to in my earlier post. I strongly recommend that you download the attachments and play with them. Just play around and see how they work. I'm sure having done so you will appreciate the whole subject so much more easily.

              Comment

              Working...