Chris
Chris

Reputation: 151

MS Access TextBox events won't fire

I am trying to filter my listbox lstOutputon the fly as the user types into my textbox txtInput however none of the key events on my textbox fire until I click my listbox and then go back to my textbox.

Here is the code I am using

Private Sub txtInput_KeyPress(KeyAscii As Integer)
Dim strSQL As String

strSQL = "SELECT Patient.PatientID, Patient.FName, Patient.LName " & _
    "FROM Patient " & _
    "WHERE (((Patient.FName)=[Forms]![New Session]![txtInput]) OR ((Patient.LName)=[Forms]![New Session]![txtInput])) " & _
    "ORDER BY Patient.[FName], Patient.[LName];"

Me.lstResults.RowSource = strSQL
Me.lstResults.Requery
End Sub

I have tried the KeyUp, KeyDown, Dirty, Change events as well but to avail. The only one that works is the AfterUpdate event but I won't the results to filter as the user types and not after pressing enter.

Upvotes: 0

Views: 1166

Answers (1)

DivisionX
DivisionX

Reputation: 26

OnChange is the event you want to use, this event triggers whenever you make a change to the TEXT in the textbox. Now the default property of a textbox is VALUE. As you type the .TEXT of the textbox is changed, when you hit enter/tab the .VALUE is changed. You need to reference to the .TEXT like:

[Forms]![New Session]![txtInput].Text

This should hopefully get you started

Upvotes: 1

Related Questions