Question : MS Acceess 2002 Dynamically changed listbox

I wanted to create a google-style customers and jobs lookup where I type in a Textbox, and Listbox'es rowsource query is modified according to whatever I type (dynamically)
The folowing code works fine when it comes to the customers.
but it does not works on the same Textbox - Listbox combination on the Jobs  lookup.
Error message: You can't modify control's property when control is not in focus.
Why this code works on one pair of controls and not on another?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Private Sub OR2_COMPANY_Enter()
   Me.TabCtl1.Value = 2 'this makes customer's listbox tab visible
End Sub

Private Sub OR2_COMPANY_Change()
   List_Customers.RowSource = "SELECT CUSTOMERS.ID,CUSTOMERS.CUST_ID, CUSTOMERS.CUST_COMP,CUSTOMERS.CUST_NAME, CUSTOMERS.CUST_PHONE FROM CUSTOMERS where (CUSTOMERS.CUST_COMP like '*" & OR2_COMPANY.Text & "*') or (CUSTOMERS.CUST_NAME like '*" & OR2_COMPANY.Text & "*')"
    List_Customers.Requery
     If List_Customers.ListCount > 0 Then
      List_Customers.Enabled = True
       Else
        List_Customers.Enabled = False
         End If
 
End Sub

Answer : MS Acceess 2002 Dynamically changed listbox

Error message: You can't modify control's property when control is not in focus.

I believe the error message is referring to your use of the .Text property on line#6, which does require focus on the control.  Use .Value  instead, which does not require focus.

if, for some reason, you want to use the .Text property, then you must set focus on the listbox before accessing the .Text property.

Change the applicable portion of your  code line #6
           OR2_COMPANY.Value & "*') or (CUSTOMERS.CUST_NAME like '*" & OR2_COMPANY.Value & "*')"
   
Random Solutions  
 
programming4us programming4us