473,408 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Combobox search while you type

Hi all,

In February I had a similar query on the following thread: https://bytes.com/topic/access/answe...-selected-item

The answer given works fine but is a little clunky - e.g. when the user types multiple keys in a row it executes the change event multiple times so the typing is behind on screen. Is there anyway to make it so that it only queries once when the user has stopped typing rather than every time? I would guess it would be some timer event but I've never used them before and I'm not sure how to get it to work!
Nov 17 '15 #1
3 2378
zmbd
5,501 Expert Mod 4TB
Open your form in design view.
Properties
Form
Events
[On Timer] event
This is where you will place your code
This will trigger every time the timer counts down from the time the form opens; thus you need a flag - tempvars collection comes to mind. I have in the past use the form Tag property that I set to 0 on load and 1 in the other events. In the timer event itself I reset the tag to zero once the action has taken place.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer()
  2.     If Me.Tag Then
  3.         MsgBox "timer event tag is" & Me.Tag
  4.         Me.Tag = 0
  5.     End If
  6. End Sub
  7.  
[Timer Interval] == 30seconds ==> 30000
thus 5seconds would be 5000

Now in the [On Change] events you need to have for say a 10 second delay:
Expand|Select|Wrap|Line Numbers
  1. Me.TimerInterval = 10000
  2. me.tag = 1
Now every time the event fires, it resets the interval and sets the flag. If the interval expires before the next event resets then [on timer] event fires, runs its course, and clears the flag.

Move all of your other query code into either the [On Timer] event or as a private procedure(s) within the form or as a standard module and then call the procedure from the event, either way.

Hope that's clear - I've only glanced at jforbes code so you'll have to play with things a bit to get the timing and key/mouse-trapping just right.


This is along the same idea as the idle out timer found here:
home > topics > microsoft access / vba > insights > inactivity detection in access
Nov 18 '15 #2
jforbes
1,107 Expert 1GB
This seemed like a really bad idea, but I gave it a whirl anyway. I reworked my test version of this and the following is what I came up with. I was pleasantly surprised as it seems to work pretty well:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private nDelay As Long
  5.  
  6. Private Sub Form_Load()
  7.     ' Setup KeyPress Delay
  8.     nDelay = 1000
  9. End Sub
  10.  
  11.  
  12. ' Set and Reset the Form Timer as needed
  13. Private Sub setTimer()
  14.     Me.TimerInterval = nDelay
  15. End Sub
  16. Private Sub resetTimer()
  17.     Me.TimerInterval = 0
  18. End Sub
  19.  
  20.  
  21. ' ComboBox Events
  22. Private Sub cboPeople_GotFocus()
  23.     ' Reset the Dropdown List
  24.     Dim sSQL As String
  25.     sSQL = sSQL & "SELECT FullName "
  26.     sSQL = sSQL & " FROM People "
  27.     If Me.cboPeople.RowSource <> sSQL Then Me.cboPeople.RowSource = sSQL
  28. End Sub
  29. Private Sub cboPeople_LostFocus()
  30.     Call resetTimer
  31. End Sub
  32. Private Sub cboPeople_Change()
  33.     Call setTimer
  34. End Sub
  35. Private Sub cboPeople_KeyDown(KeyCode As Integer, Shift As Integer)
  36.     Select Case KeyCode
  37.         Case vbKeyDown, vbKeyUp
  38.             Call setTimer
  39.         Case Else
  40.             Call resetTimer
  41.     End Select
  42. End Sub
  43.  
  44.  
  45. Private Sub Form_Timer()
  46.     Dim sSQL As String
  47.     Dim sNewLookup As String
  48.  
  49.     ' Refresh the Dropdown List for the Current Dropdown Text
  50.     sNewLookup = Nz(Me.cboPeople.Text, "")
  51.     sSQL = sSQL & "SELECT FullName "
  52.     sSQL = sSQL & " FROM People "
  53.     If Len(sNewLookup) <> 0 Then
  54.         sSQL = sSQL & " WHERE FullName LIKE '*" & sNewLookup & "*'"
  55.     Else
  56.         SendKeys "{F4}"
  57.     End If
  58.     Me.cboPeople.RowSource = sSQL
  59.     Me.cboPeople.Dropdown
  60.     Call resetTimer    
  61. End Sub
Nov 19 '15 #3
zmbd
5,501 Expert Mod 4TB
:)

I use it as a simple idle check for one of my most often left open databases that I've never bothered to split into b/f-ends. I set the event interval to about 15 minutes and the event reset is in both the form's on_current and after_update events as these are one-off entries that happen once or twice a month. On trigger, I force save the data and close the database.
Nov 19 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jan | last post by:
I am having problems trying to print a report based on a form. This is a search form only, no data input. There is a query that the form looks at, but then there are numerous comboxes that you...
2
by: VM | last post by:
How can I implement the autocomplete functionality in a Windows comboBox? Thanks.
4
by: Eric85 | last post by:
I have a question on how combo serach box work... i have a table call StudentInfo my Primary key is set to auto number (which is thier membership number) i want to be able to scan the...
3
by: Przemek M. Zawada | last post by:
Dear Group, I'm developing sample window form, using DataGridView control, which is filled with data through BindingSource, which is based on type of object, as follow: public sampleClass {...
1
by: Pascal Hagedorn | last post by:
Hello Alltogether, following problem is bugging me :) I am havin a Combobox where i can browse and select my articles. So far so good! Over the time my table "article" growed and now it is not...
1
by: Peter Herath | last post by:
i want to display results in a combo box when i select a value from another combo box. for an example i hav two tables called Project and Indicator... i want to select a project name and when i...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
3
by: =?Utf-8?B?bWVtZWFk?= | last post by:
I have a combobox displaying the full name of a customer (e.g. John Smith) and would like to go to the LAST name whenever a user presses a key while on this combobox. I have looked at the...
0
by: ali gh | last post by:
i have a combobox that shows the one field of data table . i want for new record user type new data in combobox and be add to combo items?
20
by: kashifshahzad | last post by:
See the attached ms access file. I have one combobox I want to search and select a keyword in it. usually combobox give u facility of one keyword which start with. for example I want to see the word...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.