473,508 Members | 3,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search as you type in combo box

2 New Member
Hello Everyone,


I am trying to make my combo box have a search capability and be able to narrow down the drop down list to something shorter


current function of the combo box will show the entire list
but when there are 100's of records then this method does not work too well

I would like to have the option to start typing and the drop down list narrowed down to the matching or similar string


below is sample code that i modified to match my table and field names but does not work as intended, once something is typed in then a window pops up requesting to enter parameter value

thanks in advance!


Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSample_Change()
  2.  
  3.     Dim strText, strFind
  4.  
  5.     ' Get the text that the user has typed into the combo box editable field.
  6.     strText = Me.cboSample.Text
  7.  
  8.     If Len(Trim(strText)) > 0 Then
  9.         ' Show the list with only those items containing the typed
  10.         ' letters.
  11.  
  12.         ' Create an SQL query string for the WHERE clause of the SQL
  13.         ' SELECT statement.
  14.         strFind = "Name Like '"
  15.         For i = 1 To Len(Trim(strText))
  16.             If (Right(strFind, 1) = "*") Then
  17.                 strFind = Left(strFind, Len(strFind) - 1)
  18.             End If
  19.             strFind = strFind & "*" & Mid(strText, i, 1) & "*"
  20.         Next
  21.         strFind = strFind & "'"
  22.  
  23.         strSQL = "SELECT tblSample.ID, tblSample.fieldName, SortOrder FROM tblSample Where " & _
  24.         strFind & " ORDER BY SortOrder;"
  25.  
  26.         ' Filter the combo list records using the new SQL statement.
  27.         Me.cboSample.RowSource = strSQL
  28.  
  29.     Else
  30.         ' Show the entire list.
  31.         strSQL = "SELECT tblSample.ID, tblSample.fieldName, tblSample.SortOrder FROM tblSample ORDER BY tblSample.SortOrder; "
  32.         Me.cboSample.RowSource = strSQL
  33.     End If
  34.  
  35.     ' Make sure the combobox is open so the user
  36.     ' can see the items available on list.
  37.     Me.cboSample.Dropdown
  38.  
  39. End Sub
  40.  
Dec 5 '16 #1
3 10250
jforbes
1,107 Recognized Expert Top Contributor
I think this is a very similar Question that you may want to check out: Combobox Stop Autofilling Text portion from selected item

Most likely your error is from a malformed SQL, you could use the following to help you debug it: How to Debug SQL String
Dec 5 '16 #2
ADezii
8,834 Recognized Expert Expert
I usually incorporate this type of functionality in the Change() Event of a Text Box above the Combo Box and not in the Combo Box itself. The basic Code for a 2-Column Combo Box consisting of [Last Name], [First Name] and for all matches of char(s) entered* (F*, Fr*, Fre*, etc,), would be:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtTest_Change()
  2.   Me![cboTest].RowSource = "SELECT [Last Name], [First Name] FROM Customers WHERE " & _
  3.                            "[Last Name] Like '" & Me![txtTest].Text & "*' ORDER BY " & _
  4.                            "[Last Name]"
  5. End Sub
Dec 5 '16 #3
daniel2478
2 New Member
thanks for the responses, i'll give both a try
Dec 5 '16 #4

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

Similar topics

1
6124
by: Will | last post by:
I have a combo box on a form which is based on table tblMachine. On that combo box I have four columns visible MachineNumber, description, location and type. The bound column is the MachineNumber...
0
2062
by: eruditus | last post by:
This is both a programming and a web development question so please let me know if this should be in Web Development... Anyway, I have a list derived from a database that populates a combo box. ...
3
5658
by: lushh | last post by:
hi guys. i need help on doing a search on a database. i am using ms access 2003 and the form looks like this: http://i114.photobucket.com/albums/n258/lushh_16/searchbyclientform.jpg when the...
3
2467
by: mf193 | last post by:
Hi, I have a table of around 1000 rows; patient records. Each row is individually defined by a Patient ID number which is my primary key. I have made a simple form to display patient information...
0
1842
by: imwhiteandnerdy | last post by:
i'm kinda a newbie I would appreciate some help Basically i'm setting up a search page using multiple options from a combo box Combo Box(2 options) First Name Last Name text box to the...
3
1681
by: mahesh123 | last post by:
Hi Folks, I want Help regarding the Auto search in the Combo Box. When I am pressing the characters it will move to the appropraite words in the Combo Box. For Example if the Combo Box filled...
30
26444
ADezii
by: ADezii | last post by:
This week’s Tip of the Week will clearly demonstrate how you can dynamically set the Drop Down List Width of a Combo Box to the length of the longest item in its Row Source. The inspiration for this...
3
1690
by: frontendcnp | last post by:
Hello I am trying to change the way a combo box serches. Right now it searches from the begining of field. can it be chaged to search any string of letters anywhere in field. ex: field 1= "...
3
1554
by: TomM484 | last post by:
I am trying to use a combo box (named GTLT or "greater than less than") to sort my results based on if the Formula Weight () is greater than or less than the PointValue given in another text box. ...
10
1770
by: mrijet | last post by:
Hi everybody, Can anyone guide me how to create an advanced search using combo box? For right now, I just can search using only one field which is my primary key. So now, I want to search by...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7058
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
7502
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
5635
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,...
1
5057
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...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.