Results 1 to 3 of 3
  1. #1
    brew is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    16

    Like statment

    Hi,

    Is there a way to search entire fields for example...

    Search for "mer"

    and return the field with "Homer"



    Currently I'm using a LIKE function but I'm open to anything.



    Code:
    Private Function BuildFilter() As Variant
    
        Dim varWhere As Variant
    
    
        varWhere = Null 
       
        
        ' Check for LIKE Patient Name
        If Me.txtpatname > "" Then
            varWhere = varWhere & "[PatientName] LIKE """ & Me.txtpatname & "*"" AND "
        End If
        
        ' Check if there is a filter to return...
        If IsNull(varWhere) Then
            varWhere = ""
        Else
            varWhere = "WHERE " & varWhere
            
            ' strip off last "AND" in the filter
            If Right(varWhere, 5) = " AND " Then
                varWhere = Left(varWhere, Len(varWhere) - 5)
            End If
        End If
        
        BuildFilter = varWhere
        
    End Function

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Like is the correct operator. You might need the wildcard on both sides of the input.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    brew is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    16
    Thanks June7

    After a bit of playing around with wildcard location the following seem to of worked.

    Code:
    Private Function BuildFilter() As Variant
    
        Dim varWhere As Variant
    
    
        varWhere = Null  ' Main filter
       
        
        ' Check for LIKE Patient Name
        If Me.txtpatname > "" Then
            varWhere = varWhere & "[PatientName] LIKE ""*" & Me.txtpatname & "*"" AND "
        End If
        
        ' Check if there is a filter to return...
        If IsNull(varWhere) Then
            varWhere = ""
        Else
            varWhere = "WHERE " & varWhere
            
            ' strip off last "AND" in the filter
            If Right(varWhere, 5) = " AND " Then
                varWhere = Left(varWhere, Len(varWhere) - 5)
            End If
        End If
        
        BuildFilter = varWhere
        
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Syntax Error on Update Statment
    By TinaCa in forum Programming
    Replies: 2
    Last Post: 09-14-2011, 05:53 PM
  2. Error message for criteria statment
    By macattack03 in forum Queries
    Replies: 1
    Last Post: 04-23-2011, 11:21 AM
  3. IF statment criteria??
    By cthai in forum Queries
    Replies: 1
    Last Post: 03-19-2011, 02:51 AM
  4. SQL statment structure
    By oss_ma in forum Programming
    Replies: 1
    Last Post: 05-13-2007, 02:08 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums