Results 1 to 8 of 8
  1. #1
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182

    Syntax: Wild Character with a String in VBA? - Microsoft Community

    Hello



    I am using the following code (along with a module) to search for a string of text.

    Private Sub btnSuspectORSearch_Click()
    Dim strCriteria As String

    strCriteria = "FindAnyWord([Suspect Name],""" & Me.SuspectField & """)"
    strCriteria = strCriteria & "OR FindAnyWord([Suspect Information.Suspect Alias],""" & Me.SuspectField & """)"

    DoCmd.OpenForm "frmSuspectSearch", _
    WhereCondition:=strCriteria, _
    WindowMode:=acDialog
    End Sub

    How do I add the Like "*" qualifier to both ends for both fields I am searching through? For example, in a simple query, I would do Like "*" & WORD & "*"

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    we dont know what FindAnyWord does.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I agree with Ranman256. Not enough info and no context
    Please give us
    -a description of what you're trying to accomplish in plain English(no jargon),
    -the design of table(s) involved,
    -the code related to the function FindAnyWord.

    Did you test your function with some sample data and ensure it works consistently, before getting involved with the Form?
    Breaking the issue into steps and solving each, then combinations of steps is a good learning tool and usually quite efficient with your time.

    Good luck

  4. #4
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    Please forgive me! I am still learning Access.

    The FindAnyWord function is below:

    Public Function FindAnyWord(varFindIn, strWordList As String) As Boolean

    Dim var
    Dim aWords

    aWords = Split(strWordList, ",")

    For Each var In aWords
    If FindWord(varFindIn, var) Then
    FindAnyWord = True
    Exit Function
    End If
    Next var

    End Function

    Basically, I am trying to create a search form that searches through multiple fields across multiple tables (ie: the whole database). I have been using the FindAnyWord function to help me. If I search for "John,Smith,Anderson" I will get a return of all fields that contain either John, Smith, or Anderson. However, If I search for "Ander", I will not get a return of Anderson.

    I want to be able to do that.

    Please let me know if there is anything more I need to say

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    zashaikh,

    You should keep your comments in this thread --not in the Code Repository.

    In response to your message that has just been posted:
    ***************
    This is useful. Thanks! But my not all my tables have primary keys :/
    As such, I can not search anything
    Every table should have a Primary Key. rule #2

    Review the info on Codd's rules to help resolve your issue.

  7. #7
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    I know. Unfortuanely, I was not the one who designed my company's database. And I would rather not go around doing anything that could possible break it

  8. #8
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Have used this line before:
    strWhere = strWhere & " AND ProjectDescription Like '*" & Me!ProjectDescription & "*'"

    Not sure but maybe with your lines:
    strCriteria = "Where [Suspect Name] Like '*" & Me.SuspectField & "*' OR [Suspect Information.Suspect Alias] Like '*" & Me.SuspectField & "*'"

    or

    strCriteria = "Where [Suspect Name] Like '*" & Me.SuspectField & "*'"
    strCriteria = strCriteria & "OR [Suspect Information.Suspect Alias] Like '*" & Me.SuspectField & "*'"

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

Similar Threads

  1. DLookup 2nd character in a text string
    By DubCap01 in forum Forms
    Replies: 5
    Last Post: 03-06-2015, 02:37 PM
  2. How do I return last character in a string?
    By SSgtBarry in forum Queries
    Replies: 4
    Last Post: 06-22-2014, 08:10 PM
  3. Dim As String syntax help
    By Kirsti in forum Programming
    Replies: 11
    Last Post: 07-29-2013, 05:29 PM
  4. Replies: 6
    Last Post: 06-07-2013, 09:45 AM
  5. Microsoft Access 2003 Import Issue- randomly cutting out first character
    By Bertimismaximus in forum Import/Export Data
    Replies: 9
    Last Post: 09-13-2011, 02:53 PM

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