Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2005
    Posts
    2

    Unanswered: Need Help with Search Function in VBA

    I trying to search for a word in my database and return every word or phrase that the word is associated with. For instance, I have the search function working so that if I search for a specific word or phrase in a specific column, it returns just that. I would like to be able to bring in all the records that are associated with that word, words or phrase. I have tried using the "LIKE", but was unsuccessful. Can someone please help.
    I will provide the code I have so far. You have to add a textfield (artifactSearch) and a button (Search_Click(). You will need to create a column named ArtifactName and populate the rows with like or similiar spelling. Use the code below

    Option Compare Database

    Private Sub Search_Click()

    Dim strArtifact As String
    Dim strSearch As String

    'Check artifactSearch for Null value or Nill Entry first.


    If IsNull(Me![artifactSearch]) Or (Me![artifactSearch]) = "" Then
    MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
    Me![artifactSearch].SetFocus
    Exit Sub
    End If
    '---------------------------------------------------------------

    'Performs the search using value entered into artifactSearch
    'and evaluates this against values in Artifacts

    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("ArtifactName")
    DoCmd.FindRecord Me!artifactSearch


    ArtifactName.SetFocus
    strArtifact = ArtifactName.Text
    artifactSearch.SetFocus
    strSearch = artifactSearch.Text

    'If matching record found sets focus in Artifacts and shows msgbox
    'and clears search control


    If strArtifact = strSearch Then
    MsgBox "Match Found For: " & strSearch, , "Congratulations!"
    ArtifactName.SetFocus
    artifactSearch = ""


    'If value not found sets focus back to artifactSearch and shows msgbox
    Else
    MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", , "Invalid Search Criterion!"
    artifactSearch.SetFocus
    End If
    End Sub



  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Define "associated with"

    Bowl = Bowel
    Bowl = fowl
    Bowl = Cup

    ???
    Inspiration Through Fermentation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •