Question Searching for a value from different lists using an ambiguous title....

CarysW

Complete Access Numpty
Local time
Today, 10:37
Joined
Jun 1, 2009
Messages
213
I'm creating a user friendly search function for my DB. I have a form which shows the search results with a 'Search' button which brings up a small Search Box. My Search Box has a Combo box whicvh is populated from a list I have written, it includes Name, Account number, Town, Postcode. Account number, town and postcode all work fine when searching - my problem comes when I try to search for name as in my actual list of accounts there are 2 fields; 'Business Name' and 'Trading As'. I want my users to be able to search for both of these fields under the 'Name' option so as not to complicate things - is this something I can put into the code or do I need to change something on my Search Box or Table or the query that the Search form gets it's information from?

Below is the code that I've used(I found the search box idea as a template on the web and changed it accordingly).

Code:
 'Generate search criteria
        GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
        
         'Filter frmSearchA based on search criteria
        Form_frmSearchA.RecordSource = "select * from qrySearchF where " & GCriteria
        Form_frmSearchA.Caption = "qrySearchF (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
 
This is pretty simple, you just need to make an If construction that "If combo = "Name" then"
search in 2 fields
else
search in 1 field
endif

Does that make sense to you?
 
This is pretty simple, you just need to make an If construction that "If combo = "Name" then"
search in 2 fields
else
search in 1 field
endif

Does that make sense to you?


Hmm...I think so.

Not sure how to write the 'search in 2 fields' bit though....:confused:
 
2 field search ... use an OR for that..
Something like so:
If Combo = "Name"
GCriteria = ""
GCriteria = GCriteria & " Field1 LIKE '*" & txtSearchString & "*'"
GCriteria = GCriteria & " OR Field2 LIKE '*" & txtSearchString & "*'"

Then continue as per normal...
 
2 field search ... use an OR for that..
Something like so:
If Combo = "Name"
GCriteria = ""
GCriteria = GCriteria & " Field1 LIKE '*" & txtSearchString & "*'"
GCriteria = GCriteria & " OR Field2 LIKE '*" & txtSearchString & "*'"

Then continue as per normal...

Hmm..can't get it to work - at which point in the code do I need to add it?
 
What do you have that doesnt work?

I have dropped it into the code after:
Code:
 'Generate search criteria
        GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
        
         'Filter frmSearchA based on search criteria
        Form_frmSearchA.RecordSource = "select * from qrySearchF where " & GCriteria
        Form_frmSearchA.Caption = "qrySearchF (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"

Which is probably completely the wrong thing.

Have changed 'Combo' to cboSearchField and Field 1 to Business Name, Field 2 to Trading As.


When I do the search I receive the Enter parameter Name box, and then receive an error.

How wrong am I? :o
 
1) Dont drop it after that code but into
You need to change the GCriteria...
Code:
If combo = "Name" 
My GCriteria
else
Your GCriteria normal line
End if

Query stuff
Also if your column names have spaces in them (which they SHOULD NOT HAVE) make sure to enclose the column names by []... I.e. [Trading As]
 
1) Dont drop it after that code but into
You need to change the GCriteria...
Code:
If combo = "Name" 
My GCriteria
else
Your GCriteria normal line
End if

Query stuff
Also if your column names have spaces in them (which they SHOULD NOT HAVE) make sure to enclose the column names by []... I.e. [Trading As]


It works!! :D Thank you, I would add to your rep but it wont let me until i spread it aroumd a bit more! :eek:
 
It works!! :D Thank you, I would add to your rep but it wont let me until i spread it aroumd a bit more! :eek:

Guess I should stop helping you :)

Not fussed about it working, I am more intrested in "do you now see what is going on??" so you can do it yourself next time and/or show someone else how to do something simular! :D :cool:
 
Guess I should stop helping you :)

Not fussed about it working, I am more intrested in "do you now see what is going on??" so you can do it yourself next time and/or show someone else how to do something simular! :D :cool:

I think I do, I'm telling it that if the combo is pointing to name then it needs to look in those 2 fields, if not let it do it's own thing.
 
Yes, you can so something simular to allow for wildcard or exact searches to add *x* or only search for x.

Any many more happy applications :)
 

Users who are viewing this thread

Back
Top Bottom