method or data member not found (1 Viewer)

tmarsh

tmarsh
Local time
Today, 03:52
Joined
Sep 7, 2004
Messages
89
Getting method or data member not found error on a list box in a search form. I have 2 unbound text boxes linked to a list box to search fields in a query. It's failing at Me.SearchResults.Requery. I don't have a lot of experience of VBA, I followed a tutorial to get the search form. Any help appreciated.
 

Minty

AWF VIP
Local time
Today, 03:52
Joined
Jul 26, 2013
Messages
10,371
You will need to post up the full code you are using
Please use the code tags in the reply menu </> to put the code in.
 

tmarsh

tmarsh
Local time
Today, 03:52
Joined
Sep 7, 2004
Messages
89
Thanks. This is in the search for text box in On Change:
Code:
[COLOR="Green"]'Create a string (text) variable[/COLOR]
    Dim vSearchString As String

[COLOR="Green"]'Populate the string variable with the text entered in the Text Box SearchFor[/COLOR]
    vSearchString = SearchFor.Text

[COLOR="Green"]'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[/COLOR]
    SrchText.Value = vSearchString

[COLOR="Green"]'Requery the List Box to show the latest results for the text entered in Text Box SearchFor[/COLOR]
    Me.SearchResults.Requery

[COLOR="Green"]
'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[/COLOR]
    If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
        Exit Sub
    End If

[COLOR="Green"]'Set the focus on the first item in the list box[/COLOR]
    Me.SearchResults = Me.SearchResults.ItemData(1)
    Me.SearchResults.SetFocus
[COLOR="Green"]
'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of  the List Box[/COLOR]
    DoCmd.Requery
[COLOR="Green"]
'Returns the cursor to the the end of the text in Text Box SearchFor[/COLOR]
    Me.SearchFor.SetFocus

    If Not IsNull(Len(Me.SearchFor)) Then
        Me.SearchFor.SelStart = Len(Me.SearchFor)
    End If
 

tmarsh

tmarsh
Local time
Today, 03:52
Joined
Sep 7, 2004
Messages
89
Should have said the 2 unbound text boxes used are SearchFor, and SrchText with SrchText's Visible property to No.
 

Gasman

Enthusiastic Amateur
Local time
Today, 03:52
Joined
Sep 21, 2011
Messages
14,317
And what is the name of the listbox?

Are you using 'Option Explicit' ?
 

tmarsh

tmarsh
Local time
Today, 03:52
Joined
Sep 7, 2004
Messages
89
And what is the name of the listbox?

Are you using 'Option Explicit' ?
It is SearchResults and I've just noticed I hadn't named it that. Done so now and getting runtime error 2465 - can't find the field '|1'

Code:
Option Compare Database

Private Sub SearchFor_Change()
[COLOR="DarkGreen"] 'Create a string (text) variable[/COLOR]
    Dim vSearchString As String

[COLOR="DarkGreen"] 'Populate the string variable with the text entered in the Text Box SearchFor[/COLOR]
    vSearchString = SearchFor.Text

[COLOR="DarkGreen"] '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[/COLOR]
    SrchText.Value = vSearchString

[COLOR="DarkGreen"] 'Requery the List Box to show the latest results for the text entered in Text Box SearchFor[/COLOR]
    Me.SearchResults.Requery

[COLOR="DarkGreen"]
'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[/COLOR]
    If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
        [COLOR="DarkGreen"] 'Set the focus on the first item in the list box[/COLOR]
            Me.SearchResults = Me.SearchResults.ItemData(1)
            Me.SearchResults.SetFocus
        [COLOR="DarkGreen"] 'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of  the List Box[/COLOR]
            DoCmd.Requery
        [COLOR="DarkGreen"] '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[/COLOR]
            Me.SearchFor = vSearchString
            Me.SearchFor.SetFocus
            Me.SearchFor.SelStart = Me.SearchFor.SelLength
            
        Exit Sub
    End If

[COLOR="DarkGreen"] 'Set the focus on the first item in the list box[/COLOR]
    Me.SearchResults = Me.SearchResults.ItemData(1)
    Me.SearchResults.SetFocus

[COLOR="DarkGreen"] 'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of  the List Box[/COLOR]
    DoCmd.Requery

[COLOR="DarkGreen"] 'Returns the cursor to the the end of the text in Text Box SearchFor[/COLOR]
    Me.SearchFor.SetFocus

    If Not IsNull(Len(Me.SearchFor)) Then
        Me.SearchFor.SelStart = Len(Me.SearchFor)
    End If
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 03:52
Joined
Sep 21, 2011
Messages
14,317
You need to say what line the error occurs? :-(
 

tmarsh

tmarsh
Local time
Today, 03:52
Joined
Sep 7, 2004
Messages
89
code.png
 

Minty

AWF VIP
Local time
Today, 03:52
Joined
Jul 26, 2013
Messages
10,371
The [Colour] [/Colour] are BB or HTML Bulletin borad instructions not VBA code.

You need to remove all of them.
 

tmarsh

tmarsh
Local time
Today, 03:52
Joined
Sep 7, 2004
Messages
89
The [Colour] [/Colour] are BB or HTML Bulletin borad instructions not VBA code.

You need to remove all of them.
Working now. I had pasted the code in and thought the green was commented out bits! Thanks again.
 

Minty

AWF VIP
Local time
Today, 03:52
Joined
Jul 26, 2013
Messages
10,371
Glad you have it sorted out.
Good Luck with the rest of it !
 

Users who are viewing this thread

Top Bottom