Listbox refresh

  • Thread starter Thread starter Cind.
  • Start date Start date
C

Cind.

Hello,

Another small question on listboxes. I have users
entering data into a textbox and it refreshes the listbox
with the results as they type. However, there is a lot
of data and thus if they type fast, it goes very slow.
Is there anyway to 'lag' the change event of a textbox to
wait a certain time period after its changed? Thanks !

Cind
 
Do you need to use the change event? That fires for every character!

Other events to consider are OnExit, LostFocus, BeforeUpdate, AfterUpdate.

Depending on your need, one of these may meet your needs and are not fired
for every character.
 
Hi Cind,

You could use the TimerInterval property and OnTimer event of the form to
delay the response of the query. Within the change event of the text box,
set the TimerInterval property and a global variable that contains the text
they've typed. In the OnTimer event, check the current contents of the text
box against the global variable to see if the text has changed. If it has
changed, within the interval specified, then exit the sub. Otherwise, run
the query that feeds the list.

Hope this helps,
- Glen
 
Larry,

Essentially I have exactly what is there except for the
following in the change event:

Me.Refresh
Me.txtListTest.SelStart = Me.txtListTest.SelLength + 1

I don't know that much with access so i dont exactly see
how this lags the change event. Otherwise, our code is
very similar. Thanks

-----Original Message-----
Ok, interesting.

I never tried this in Access, there is a control in VB that does this for
you, so I did a quicky to put something together and came up with the
following.

Form named "Form1"
Textbox named "txtListTest"
Listbox named "lstNames"
Table named "Table1", column with a bunch of names called "test".

The rowsource for the listbox is as follows:
SELECT Table1.test
FROM Table1
WHERE (((Table1.test) Like [Forms]![Form1]! [txtListTest] & "*"))
ORDER BY Table1.test;

Then in the Change event for the textbox, I have the following code:
Me.lstNames.Requery
Me.Refresh
Me.txtListTest.SelStart = Me.txtListTest.SelLength + 1

The key is the LIKE criteria with the asterisk(*) being appended to what's
typed in the textbox. But then, you probably already know this.

I have about 20 names in the table, and this responds pretty quickly. I
didn't go into adding them to the table, but I figure you have that part.

I also don't know if this is any different from what you have, or any
better, just something I came up with in 5 minutes of playing with it. Love
to see what you end up with though.

HTH


Cind said:
Larry,

Actually it is primarily used to search for every char
they enter. Think the help index in any program,
sometimes just one char is enough to see on the listbox
what you want. However, sometimes 1 isnt enough, and
they know the first 10 chars for it for instance, so the
user writes 10 chars in quickly and it goes very slow
because it is 'querying' every char. thats why id like
it to pause for a bit (less then a second) after each
char to see if they were going to write more.. any help?

Cind
needs
and are not fired textbox
to


.
 
OK, how familiar are you with VBA (Visual Basic for Applications)? Your
response to this question will gauge the detail in any examples I provide.
:~)-

- Glen
 
OK, roll up your sleeves and get ready to get your hands dirty because we're
going under the hood. :~)-

First of all you can forget about the global variable. It seems I was
mistaken and it's not needed for this scenario after all which should help
to simplify things a bit.

Two events to work with are the Change event of the text box, and the Timer
event of the form. In the Change event, we will set the timer interval:
----------
Private Sub MyTextBox_Change()

' Reset the timer interval (also resets any pending timer events)
Me.TimerInterval = 1000 ' Sets the timer to 100 milliseconds (1 second,
recommended)

End Sub
----------

Now, in the Timer event, we will update the listbox accordingly:
----------
Private Sub Form_Timer()

Dim strSQL As String ' SQL string to update listbox

' First we turn off the timer
Me.TimerInterval = 0

' Then we update the listbox
strSQL = "SELECT [MyField1], [MyField2], [MyField3] FROM [MyTable] " & _
"WHERE ([MyField] = '" & MyTextBox.Text & "');"
MyListBox.RowSource = strSQL
MyListBox.Requery

End Sub
----------
You must use the Text property of the textbox during real-time operation as
the Value property does not get updated until the textbox loses focus. The
SQL string can be basically rebuilt from a query you design using the query
builder in access. Just change the view to SQL View in the query, and
you'll see a statement very much like the one I've assigned to the string.

This should get you moving in the right direction. If you have any
questions, please let me know.

- Glen
 
Hi,

It works great (as much as it was me - mine looks a
little more complicated than what u got, but i got the
idea) thanks a lot, im impressed.

Cind
-----Original Message-----
OK, roll up your sleeves and get ready to get your hands dirty because we're
going under the hood. :~)-

First of all you can forget about the global variable. It seems I was
mistaken and it's not needed for this scenario after all which should help
to simplify things a bit.

Two events to work with are the Change event of the text box, and the Timer
event of the form. In the Change event, we will set the timer interval:
----------
Private Sub MyTextBox_Change()

' Reset the timer interval (also resets any pending timer events)
Me.TimerInterval = 1000 ' Sets the timer to 100 milliseconds (1 second,
recommended)

End Sub
----------

Now, in the Timer event, we will update the listbox accordingly:
----------
Private Sub Form_Timer()

Dim strSQL As String ' SQL string to update listbox

' First we turn off the timer
Me.TimerInterval = 0

' Then we update the listbox
strSQL = "SELECT [MyField1], [MyField2], [MyField3] FROM [MyTable] " & _
"WHERE ([MyField] = '" & MyTextBox.Text & "');"
MyListBox.RowSource = strSQL
MyListBox.Requery

End Sub
----------
You must use the Text property of the textbox during real-time operation as
the Value property does not get updated until the textbox loses focus. The
SQL string can be basically rebuilt from a query you design using the query
builder in access. Just change the view to SQL View in the query, and
you'll see a statement very much like the one I've assigned to the string.

This should get you moving in the right direction. If you have any
questions, please let me know.

- Glen



Cind said:
Cind,

Not very much at all, I have the set timer to 100 right
now, i have an ontimer event, but i dont really get where
and how to declare a global variable and how to use it to
lag the particular sub . Thanks

Cind
id
like


.
 
Back
Top