473,408 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

need to search for partial instead of exact match

I have the following code attached to a search button on a form that runs a
query. It works great, except that the search for Last Name only returns
exact matches. It is even case sensitive. Anybody have an idea of what I
need to add or change. It is the first If Then statement that I need to
search on partial matches. I've tried to use the like operator, but I just
get syntax errors.

If Not IsNothing(Me.LastName) Then
strSearch = "[LastName]= " & "'" & Me![LastName] & "'"
End If

If Not IsNothing(Me.ssNum) Then
strSearch = "[ssNumber]=" & "'" & Me![ssNum] & "'"
End If

If Not IsNothing(Me.ClientId) Then
strSearch = "[tblClient.ClientId]=" & "'" & Me![ClientId] & "'"
End If

If Not IsNothing(Me.phNum) Then
strSearch = "[Phone1]=" & "'" & Me![phNum] & "'"
End If

If IsNothing(strSearch) Then
MsgBox "No criteria specified.", 32
Exit Sub
End If
DoCmd.OpenForm "frmClaimMain", , , strSearch

If Forms!frmClaimMain.RecordsetClone.RecordCount = 0 Then
MsgBox "No Clients meet your criteria", 64
DoCmd.ShowAllRecords
Me.Visible = True
Exit Sub
End If
DoCmd.Close acForm, Me.Name
Nov 12 '05 #1
2 7094
John, thank you.
You can't imagine what you just did for me. Those 2 stars you put in my code
were the reason for my syntax error when I tried to use the like operator.
This application was nearly finished 6 months ago and that little problem
caused me to put it away for awhile. I was really under pressure to get it
finished. Now I can tie up the loose ends. Thanks again.

You asked to see my IsNothing function. Here it is.

Function IsNothing(varToTest As Variant) As Integer
' Tests for a "logical" nothing based on data type
' Empty and Null = Nothing
' Number = 0 is Nothing
' Zero length string is Nothing
' Date/Time is never Nothing

IsNothing = True

Select Case VarType(varToTest)
Case vbEmpty
Exit Function
Case vbNull
Exit Function
Case vbBoolean
If varToTest Then IsNothing = False
Case vbByte, vbInteger, vbLong, vbSingle, vbDouble, vbCurrency
If varToTest <> 0 Then IsNothing = False
Case vbDate
IsNothing = False
Case vbString
If (Len(varToTest) <> 0 And varToTest <> " ") Then IsNothing =
False
End Select

End Function
"John Mishefske" <mi****@execpc.com> wrote in message
news:vm************@corp.supernews.com...
Larry wrote:
I have the following code attached to a search button on a form that runs a query. It works great, except that the search for Last Name only returns
exact matches. It is even case sensitive. Anybody have an idea of what I
need to add or change. It is the first If Then statement that I need to
search on partial matches. I've tried to use the like operator, but I just get syntax errors.
Try

strSearch = "[LastName] Like '*' & '" & Me![LastName] & "' & '*'"
If Not IsNothing(Me.LastName) Then
strSearch = "[LastName]= " & "'" & Me![LastName] & "'"
End If


We don't have the code to your IsNothing() procedure - can we take a look?
If Not IsNothing(Me.ssNum) Then
strSearch = "[ssNumber]=" & "'" & Me![ssNum] & "'"
End If


This is going to overwrite the previous strSearch - were you hoping to

match multiple criteria? In other words, only the last control with some value in it is going to be passed to the "frmClaimMain" form.
If Not IsNothing(Me.ClientId) Then
strSearch = "[tblClient.ClientId]=" & "'" & Me![ClientId] & "'"
End If

If Not IsNothing(Me.phNum) Then
strSearch = "[Phone1]=" & "'" & Me![phNum] & "'"
End If

If IsNothing(strSearch) Then
MsgBox "No criteria specified.", 32
Exit Sub
End If


DoCmd.OpenForm "frmClaimMain", , , strSearch

If Forms!frmClaimMain.RecordsetClone.RecordCount = 0 Then
MsgBox "No Clients meet your criteria", 64
DoCmd.ShowAllRecords
Me.Visible = True
Exit Sub
End If
DoCmd.Close acForm, Me.Name


--
'-------------------------------
' John Mishefske
'-------------------------------

Nov 12 '05 #2
Larry wrote:
John, thank you.
You can't imagine what you just did for me. Those 2 stars you put in my code
were the reason for my syntax error when I tried to use the like operator.
This application was nearly finished 6 months ago and that little problem
caused me to put it away for awhile. I was really under pressure to get it
finished. Now I can tie up the loose ends. Thanks again.
You're welcome. Glad I could help.
You asked to see my IsNothing function. Here it is.


I just thought it may be part of the problem.

--
'-------------------------------
' John Mishefske
'-------------------------------

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Josh | last post by:
I've got a search running from PHP with the following SQL: $results = mysql_query("SELECT DISTINCT ForumThread.id as threadId, ForumThread.Subject as threadTopic, ForumThread.ID as threadId,...
2
by: Andy | last post by:
Hi... i'm trying to understand the concept of function name overloading in c++. to understand the resolving system it's important to understand the diffrent levels of typecasting (exact match,...
2
by: Wayne Shu | last post by:
Hi everyone. In the following program, foo is an ambiguous call. #include <iostream> using namespace std; void foo(int *); void foo(int (&));
2
by: Slippy27 | last post by:
I'm trying to modify a find/replace script which iterates through a file A and makes replacements defined in a csv file B. My original goal was to change any line in file A containing a search string...
6
by: Mr.SpOOn | last post by:
Hi, I'd like to use regular expressions to parse a string and accept only valid strings. What I mean is the possibility to check if the whole string matches the regex. So if I have: I can...
0
by: Lie Ryan | last post by:
On Sun, 26 Oct 2008 17:51:29 +0100, Mr.SpOOn wrote: re.compile('a*b*$') $ matches the end of a string, or in MULTILINE mode, the end of a line (right before newline) Symmetrically, ^...
4
by: nk28 | last post by:
I am having problem in re module of python. when i do a call of match function it returns true if first of the expression is true. For Eg :- Expression like (+()*) to denote ...
2
by: Neil Gilbert | last post by:
Ok i am fudging a legacy CRM system and i need to hide a button on the script using client side javascript. I am trying to hide a button on the screen based on the URL containing the word...
23
by: tetsuo2030 | last post by:
Hi all, I have two fields in a query: and . is a list of comma-separated paragraph numbers (like 1.0, 1.1, 1.1.2, etc); is just "1.0" or "1.1.2" or the like. I wanted to create a third field...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.