03-09-05, 13:03 #1Registered User
- 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!"
'Performs the search using value entered into artifactSearch
'and evaluates this against values in Artifacts
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!"
03-09-05, 13:09 #2Village Idiot
- Join Date
- Jul 2003
Define "associated with"
Bowl = Bowel
Bowl = fowl
Bowl = Cup
???Inspiration Through Fermentation