Searching

slide

Registered User.
Local time
Yesterday, 18:12
Joined
Apr 4, 2008
Messages
24
Ok I've setup my form to display a query and I need some way for the user to search for a unique record. I'd like to have at the top of the form an area where they can select what field to search, maybe some options for search and then their search string and then they can add more like that if they need to. is this possible? Can anyone help me create this or is this explained somewhere already? thanks!
 
I have done this before. I will tell you, it is way easier to predetermine which fields they are going to search. For instance, on one of my forms, they have a choice of searching either the name or the description, but not both. In any case, this is what you do in a very basic case:
Create an unbound text box at the top
In the afterupdate event of the text box, create your search string, like this:
Code:
strWhere ="[FieldYouWantToSearch]=" & YourTextBox 
or 
strWhere ="[FieldYouWantToSearch]='" & YourTextBox & "'" 
'if you are searching text values
or 
strWhere ="[FieldYouWantToSearch] Like '*" & YourTextBox & "*')
'if you want to search for partial matches

then you use
Code:
docmd.applyfilter , strWhere
to apply the filter or
Code:
docmd.showallrecords
to remove it
You should be able to extrapolate the more complicated case from this.
 
thanks for the start! :) what about adding a new set of search inputs. So currently I have a Combo Box that displays all fields, a search box for the term, a check box to enable/disable the term being used and a button with a "-" in it meaning to delete the term. That is for each row. When they click the "+" button i want to add a new search row.
 
I'm not sure about adding more rows. The only way I can think to do it is with a continuous form, where each record contains your searching combo box and text box. On a normal form (not set to dataentry), you will always get one blank row (for a new record) at the bottom, so that would take care of adding more rows. I have had problems with that type of thing in the past though because it seems like when you change one combo it changes all of them at the same time. Maybe other, more knowledgeable users can make some suggestions on a better way to do it.
 
well by "row" i didnt mean an entry in the database, i mean a row of controls for the search form. let me post a pic of my form...

attachment.php


The circled part is what I want to duplicate.
 

Attachments

  • SearchForm.jpg
    SearchForm.jpg
    22.3 KB · Views: 204
Im working on that now but my main roadblock at the moment is how to access a controls properties not pre-knowing its name. IE. In vba in my form i can do Me.Field1.Text and get what is in Field1, but how can I then get Field 2 etc etc without pre-progrmaming that in which I dont want to do, I want to do something like Me.Field & ID.Text but I can't figure out how to do that!
 
What if you do a for each statement instead? Like for each ctl in me.form, if ctl.controltype=accombo (I think that is what it is) then . . . (add to search string)
Or else in your code where you are adding the controls, maybe you can specify the control names? That way you would know what they are? As long as you are closing with acsaveno that should work . . .
 

Users who are viewing this thread

Back
Top Bottom