Trying the "Dynamically search multiple fields" and have a problem.

MJHirsch

New member
Local time
Today, 11:54
Joined
Jan 20, 2014
Messages
4
Access 2013

I am trying to follow the steps in the guide "Dynamically search multiple fields" but once I am done and try to test it, I get the error:

Microsoft Visual Basic
Run-time error '-2147352567 (80020009)':
You can't assign a value to this object.

The line in question is: Me.SearchResults = Me.SearchResults.ItemData(1)



For fast reference, here is the full code.

Private Sub SearchFor_Change()
'Create a string (text) variable
Dim vSearchString As String

'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_SearchAll
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
'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
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,
'and restores trailing space lost when focus is shifted to the list box
Me.SearchFor = vSearchString
Me.SearchFor.SetFocus
Me.SearchFor.SelStart = Me.SearchFor.SelLength

Exit Sub
End If

'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
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 Link is access-programmers.co.uk/forums/showthread.php?t=188663
 
You say here's the full code...

you do have a form, right?

Did you test John's database from the zip ?
 
I did try his zip file and it worked correctly.

As for mine, I used the steps from the website to try to replicate his process which resulted in the error I mentioned. I tried it twice to be sure I was not missing something.

The code I mention is the VB code he updated in his guide. I did not add the starting steps to my post.

His zip file example is EXACTLY what I am looking to create with a customer database,but seem to be fumbling in the dark.
 

Users who are viewing this thread

Back
Top Bottom