Hi,
I'm trying to filter the contents of a listbox dynamically so that as I type, the listbox is filtered with the contents of the textbox.
So far, I have a query (Query1):
The reason for the query being that I can reuse it on other forms too. Running this manually shows that this works.
The form consists of a textbox (txtCustomer), a button (cmdAdd) and a listbox (lstCustomers).
I'm using the following code:
The trouble is that everytime I type text, the listbox does not update. The first character typed in to txtCustomer causes the listbox to update albeit incorrectly but nothing happens after any subsequent characters are typed. Stepping through, I can see all the code executes but nothing changes the listbox. Clicking cmdAdd does update the listbox so at least the query side of things is working!!
What is not happening here?
Thanks
I'm trying to filter the contents of a listbox dynamically so that as I type, the listbox is filtered with the contents of the textbox.
So far, I have a query (Query1):
Code:
PARAMETERS dbb Text ( 255 );
SELECT Customers.Customer, Customers.ID
FROM Customers
WHERE (((Customers.Customer) Like "*" & [dbb] & "*"));
The reason for the query being that I can reuse it on other forms too. Running this manually shows that this works.
The form consists of a textbox (txtCustomer), a button (cmdAdd) and a listbox (lstCustomers).
I'm using the following code:
Code:
Private Sub cmdAdd_Click()
Dim dbs As DAO.Database
Dim qdfMembers As DAO.QueryDef
Dim rsMembers As DAO.Recordset
Set dbs = CurrentDb
Set qdfMembers = dbs.QueryDefs("Query1")
qdfMembers.Parameters("dbb").Value = txtCustomer
Set rsMembers = qdfMembers.OpenRecordset
Set lstCustomers.Recordset = rsMembers
Set qdfMembers = Nothing
Set dbs = Nothing
End Sub
Private Sub txtCustomer_Change()
Dim dbs As DAO.Database
Dim qdfMembers As DAO.QueryDef
Dim rsMembers As DAO.Recordset
Set dbs = CurrentDb
Set qdfMembers = dbs.QueryDefs("Query1")
qdfMembers.Parameters("dbb").Value = txtCustomer
Set rsMembers = qdfMembers.OpenRecordset
Set lstCustomers.Recordset = rsMembers
Set qdfMembers = Nothing
Set dbs = Nothing
End Sub
The trouble is that everytime I type text, the listbox does not update. The first character typed in to txtCustomer causes the listbox to update albeit incorrectly but nothing happens after any subsequent characters are typed. Stepping through, I can see all the code executes but nothing changes the listbox. Clicking cmdAdd does update the listbox so at least the query side of things is working!!
What is not happening here?
Thanks