Problem with keyword seach (1 Viewer)

vent

Registered User.
Local time
Yesterday, 21:13
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
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:13
Joined
Feb 28, 2001
Messages
27,001
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.
 

vent

Registered User.
Local time
Yesterday, 21:13
Joined
May 5, 2017
Messages
160
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
 

isladogs

MVP / VIP
Local time
Today, 01:13
Joined
Jan 14, 2017
Messages
18,186
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:

vent

Registered User.
Local time
Yesterday, 21:13
Joined
May 5, 2017
Messages
160
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".
 

vent

Registered User.
Local time
Yesterday, 21:13
Joined
May 5, 2017
Messages
160
nevermind i got it working, thank you all!:)
 

Users who are viewing this thread

Top Bottom