Wildcards

tarcona

Registered User.
Local time
, 19:30
Joined
Jun 3, 2008
Messages
165
How do I make a wildcard search but have it smarter if you get what I am saying.

The code for my wildcard search is:

Code:
    If Not IsNull(Me.txtSearchCompany) Then
        strWhere = strWhere & "([Company] LIKE ""*" & Me.txtSearchCompany & "*"") AND "
    End If

But how I want to make my search smarter is like this:
When I type Unity in my search it comes up with Whatever Community Hospital, with the word 'unity' within 'community'. What I want the search to do is for the user just to type in Unity and Unity Hospital is found.

Thank you for your help.
 
Last edited:
if I have understood you right, try:
Code:
strWhere = strWhere & " ([Company] Like '*" & Me.txtSearchCompany & "*')"

if txtSearchcompany was Light, then the search would bring up companies called, Electric Light Company, Light Machines Ltd and SearchLight.

HTH,
Chris
 
I have a new problem. I found out how to do the wildcard search, but I want to make my wildcard search smarter. Read my original post. I just edited it somewhat.
 
Basically, when the user types in the word 'Light' I want all matches with the first word being 'Light' like Light Hospital or Light Company...not SearchLight or Pole Light or Big Bolt Lightning.
 
Simple Software Solutions

Hope nobody is searching for Scunthorpe???
 
hi,
if you only want word beginning with then alter my code as follows:
Code:
strWhere = strWhere & " ([Company] Like '" & Me.txtSearchCompany & "*')"
(I just removed the first wildcard (*) so now if txtSearchCompany is Unity, then Unity Hospital, Unity Bridge and Unity Cakes would come up.)

Is this what you want?
Chris
 
The code did not work for some reason. But that is what I want.
 
When I run the search the Debug Window comes up and points to this line as an error:

Code:
        ' Apply the string as the form's Filter.
        [COLOR=red]Me.Filter = strWhere[/COLOR]
        Me.FilterOn = True
 
What error does it give? Have you put in a debug.print strWhere to see what the contents of string actually are? I can only help so much...
 
Ok, in my search I typed in "Unity" hoping to get Unity Hospital not Community Hospital.

The Debug Window shows up and says:

Run-time error '3075'

Syntax error in string in query expression '([Company] LIKE 'Uni'.

And I click Debug and it highlights the line that I highlighted in red in the previous post.
 
What else is in strWhere before you add:
Code:
strWhere = strWhere & " ([Company] Like '" & Me.txtSearchCompany & "*')"
because I set up a table and a form with variables named exactly as above and I get no error. I need to see the whole string. Comment out the Me.filter = strWhere and replace it with:
Code:
debug.print strWhere
make sure the debug window is open when you run it. then copy & paste the contents of the debug window into a post so I can see exactly what string is produced.

Chris
 
Last edited:
I dont know if this is what you wanted but this is what it says:

([Company] Like 'Uni
 
Actually, I got it to work. THANKS for your help. I really do appreciate when you take your time out of your day to come on to here and help people like me. Thanks a bunch.
 

Users who are viewing this thread

Back
Top Bottom