text box on change event not working !!

siamandm
BronzeLounger
Posts: 1226
Joined: 01 May 2016, 09:58

text box on change event not working !!

Post by siamandm »

hello all,
i have a text box for search and a button to change the row source for a list box
when i put something in the text box and click search button it works and do the filter for me,
so i copied the on click event codes to the on change event of the text box and im expecting to do the filter same as i click on the search button . but it does not

why is that please??

Code: Select all

Private Sub txtSearch_Change()
On Error GoTo Err_txtProperty_Change
Dim sql As String

sql = "Select Products.[Product Code], Products.[Product Name] from products" _
& " Where [Product Code] like '*" & Me.txtSearch & "*'"

Me.CustomerList.Form.RecordSource = sql
Me.CustomerList.Form.Requery


Me.lstCustomer.RowSource = sql
Me.lstCustomer.Requery
Err_txtProperty_Change:

End Sub

User avatar
HansV
Administrator
Posts: 78471
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: text box on change event not working !!

Post by HansV »

Me.txtSearch is the stored value of the text box. It is updated only when you leave the text box, not while you are typing.
To refer to the text as you type, use Me.txtSearch.Text. This is only valid while txtSearch has the focus; once you have activated another control, you cannot refer to Me.txtSearch.Text any more.

So use

Code: Select all

sql = "Select Products.[Product Code], Products.[Product Name] from products" _
& " Where [Product Code] like '*" & Me.txtSearch.Text & "*'"
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1226
Joined: 01 May 2016, 09:58

Re: text box on change event not working !!

Post by siamandm »

thanks a lot now is working as expected !!!
another question please : how to make the text inside the text box selected after i finish typing or using barcod read


Regards

User avatar
HansV
Administrator
Posts: 78471
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: text box on change event not working !!

Post by HansV »

How can we know when you finish typing?
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1226
Joined: 01 May 2016, 09:58

Re: text box on change event not working !!

Post by siamandm »

HansV wrote:How can we know when you finish typing?
ok what about something like the supermarket they use bar code reader continuously ... scanning one item after another ... how doe this work please?

User avatar
HansV
Administrator
Posts: 78471
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: text box on change event not working !!

Post by HansV »

The software that comes with a barcode scanner usually has an option to send a Return character after each scan.
In Access this will trigger the After Update event of the text box.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1226
Joined: 01 May 2016, 09:58

Re: text box on change event not working !!

Post by siamandm »

thanks a lot, so we have to add after update event if we want to get around this.

regards

User avatar
HansV
Administrator
Posts: 78471
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: text box on change event not working !!

Post by HansV »

Yes - you don't want to use the On Change event for a barcode - the barcode is only valid when it's complete.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1226
Joined: 01 May 2016, 09:58

Re: text box on change event not working !!

Post by siamandm »

ok thank you very much