By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,870 Members | 2,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,870 IT Pros & Developers. It's quick & easy.

I need a VBA code for my unbound Search form.

P: 16
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.
Nov 28 '11 #1
Share this Question
Share on Google+
6 Replies


NeoPa
Expert Mod 15k+
P: 31,489
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.
Nov 28 '11 #2

P: 16
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.
Nov 29 '11 #3

100+
P: 759
Take a look here:
http://bytes.com/topic/access/answer...te#post3688063

The thread is not finalized but maybe you can find anything useful.
Nov 29 '11 #4

P: 16
Mihail,

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

Thank you.
Nov 29 '11 #5

P: 16
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.
Nov 29 '11 #6

NeoPa
Expert Mod 15k+
P: 31,489
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.

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.
Nov 29 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.