Hi all, Me Again!!!!...
So I had a search query I was using for a previous DB which worked perfectly. I am trying to use it for a new DB but the Macro for the search box doesn't seem to work.
I can't remember where I got the search code from originally (might have been here) but it worked so well.
Anyway.. here is what I have.
3 x unbound text boxes called
SearchFor
SearchResults
SrchText (This one is hidden from view)
I have a query (called QRY_SearchName) set up with the following added for the Field I am searching [Address 2] in the criteria Like "*" & [forms]![SearchName]![SrchText] & "*"
And then I have the Macro on "Change" for the SearchFor box.
The area in bold and red is where Access is highlighting the error. now I did change the names of the queries used in the search but I thought I found all the problems.
Help would be very much appreciated.
So I had a search query I was using for a previous DB which worked perfectly. I am trying to use it for a new DB but the Macro for the search box doesn't seem to work.
I can't remember where I got the search code from originally (might have been here) but it worked so well.
Anyway.. here is what I have.
3 x unbound text boxes called
SearchFor
SearchResults
SrchText (This one is hidden from view)
I have a query (called QRY_SearchName) set up with the following added for the Field I am searching [Address 2] in the criteria Like "*" & [forms]![SearchName]![SrchText] & "*"
And then I have the Macro on "Change" for the SearchFor box.
Code:
Private Sub SearchFor_Change()
'Populate the string variable with the text entered in the Text Box SearchFor
vSearchString = SearchFor.Text
'Pass the value contained in the string variable to the hidden text box SrchText,
'that is used as the sear4ch criteria for the Query QRY_SearchName
SrchText.Value = vSearchString
'Requery the List Box to show the latest results for the text entered in Text Box SearchFor
Me.SearchResults.Requery
'Tests for a trailing space and exits the sub routine at this point
'so as to preserve the trailing space, which would be lost if focus was shifted from Text Box SearchFor
If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
Exit Sub
End If
'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.[B][COLOR=red]ItemData(1)[/COLOR][/B]
Me.SearchResults.SetFocus
'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of the List Box
DoCmd.Requery
'Returns the cursor to the the end of the text in Text Box SearchFor
Me.SearchFor.SetFocus
If Not IsNull(Len(Me.SearchFor)) Then
Me.SearchFor.SelStart = Len(Me.SearchFor)
End If
End Sub
The area in bold and red is where Access is highlighting the error. now I did change the names of the queries used in the search but I thought I found all the problems.
Help would be very much appreciated.