I am trying to program a dynamic search box, wherein on the KeyPress event of a textbox, some SQL selects records from a table that are similar to whats in the textbox, however when I type something into the text box, it refreshes by nothing is displayed. When debugging, the textbox value is null, even though I have typed something in. Does anyone know why this might be happening? I have checked spelling countless times. My code can be found below. Thank you.
Code:
Private Sub txtSearch_KeyPress(KeyAscii As Integer)
Dim db As DAO.Database
Dim rsSearch As DAO.Recordset
Set db = CurrentDb()
'Setting up db, selecting all records that are similar to what is in the textbox
Set rsSearch = db.OpenRecordset("SELECT * FROM tblCustomers WHERE Forename LIKE '" & txtSearch & "'", dbOpenDynaset)
Set listCust.Recordset = rsSearch
End Sub