Parameter query

VOLLEGAAS

Registered User.
Local time
Today, 00:29
Joined
Feb 3, 2003
Messages
15
How can i get a parameter query to find records based on the SECOND word in that specific field. For example: The field "NAME" contains the first and last name, i want to be able to search for the last name (which is the second word in the "NAME" field. Is this possible and if it is how???
Thanks in advance
 
If you write a function that specifically gets the second word from the field and call the function from your query then you'll have no problems.

Something like:

Code:
Public Function GetSecondWord(ByVal strDefault As String)
   Dim intCounter As Integer
   Dim intPositions(0 To 1) As Integer
   Dim intTotal As Integer
   For intCounter = 1 To Len(strDefault)
      If Mid(strDefault, intCounter, 1) = " " Then
         If intTotal = 0 Then
            intPositions(0) = intCounter + 1
            intTotal = intTotal + 1
         ElseIf intTotal = 1 Then
            intPositions(1) = intCounter - 1
            Exit For
         End If
       End If
   Next intCoutner
   For intCounter = intPosition(0) To intPosition(1)
      GetSecondWord = GetSecondWord & Mid(strDefault, intCounter, 1)
   Next intCounter
End Function


The code can be written neater but it's just off the top of my head.
 
You'll create problems for yourself having a field called Name, it's a reserved word in access, and it would be better to have first and last names as separate fields
 
Thanks for your help, but i've solved it in a different way. The way i've solved it the query looks for the word you give as parameter in the whole field, not just the second word. This is how i've solved it:

Criteria in query:

Like "*" & [FIELD NAME] & "*"
 

Users who are viewing this thread

Back
Top Bottom