Problem with keyword seach

vent

Registered User.
Local time
Today, 06:08
Joined
May 5, 2017
Messages
160
Hi everyone, a real access novice here with a problem regarding this keyword search. Basically I have listbox with a query between two tables as a control source. The idea is for the user to type the listbox would filter itself and get shorter based on what the user types and as they type and also textboxes underneath the listbox would autopopulate. Here is my VBA for the search text box. Everytime i type even a single letter into the search i get this error that says "invalid use of Null" if someone can please guide, that would be very appreciated. Thank you.:banghead:





Private Sub txtKeywords_Change()


Dim vlocateString As String


vlocateString = txtKeywords.Text




Me.SearchResults.Requery


If Len(Me.txtKeywords) <> 0 And InStr(Len(txtKeywords), txtKeywords, " ", vbTextCompare) Then
Exit Sub
End If


Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus

DoCmd.Requery

Me.txtKeywords.SetFocus

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






End Sub
 
When it complains, do you get a dialog box for debugging that gives you option to click DEBUG? If so, choose that option and see which line is highlighted. If you hover the mouse over the variables in the line, you will see their contents and can find which one is null.
 
I get this highlighted in yellow. Do I also need to define Len and InStr?


If Len(Me.txtKeywords) <> 0 And InStr(Len(txtKeywords), txtKeywords, " ", vbTextCompare) Then
 
I get this highlighted in yellow. Do I also need to define Len and InStr?
No to both

If Len(Me.txtKeywords) <> 0 And InStr(Len(txtKeywords), txtKeywords, " ", vbTextCompare) Then

The second part doesn't make sense to me
InStr(Len(txtKeywords), txtKeywords, " ", vbTextCompare)

So you're starting at the END of txtKeywords then you are searching txtKeywords for a space after the end of txtKeywords ....?
EITHER I'm being stupid or that's daft!
 
Last edited:
Basically with the second part my intention was to return the first instance of a record that matches what the user presently typed out e.g. user types "Joh" and the first instance returned "John Smith".
 
nevermind i got it working, thank you all!:)
 

Users who are viewing this thread

Back
Top Bottom