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

    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!"
    Exit Sub
    End If

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

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

    strArtifact = ArtifactName.Text
    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!"
    artifactSearch = ""

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

  2. #2
    Join Date
    Jul 2003
    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