473,749 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can you search a listbox by a textbox value when the multiselect property isn't none?

30 New Member
Currently I am able to use a texbox to search through the listbox only when the multiselect property is set to none. But when I change the property to simple or extended my function doesn't work. Please see below
Function
Expand|Select|Wrap|Line Numbers
  1. Public Function CheckListbox(strPass As String, lstPersons As ListBox)
  2.  
  3. Dim intCurrIndex As Integer
  4.  
  5. Dim intStringLen As Integer
  6.  
  7.  
  8.  
  9. intStringLen = Len(strPass)
  10.  
  11.  
  12.  
  13. For intCurrIndex = 0 To lstPersons.ListCount - 1
  14.  
  15.          If Left$(lstPersons.ItemData(intCurrIndex), intStringLen) = strPass Then
  16.  
  17.     Exit For
  18.  
  19.   End If
  20.  
  21. Next intCurrIndex
  22.  
  23.  
  24.  
  25. lstPersons = lstPersons.ItemData(intCurrIndex)
  26.  
  27.  End Function
Calling the function
Expand|Select|Wrap|Line Numbers
  1. Private Sub abSearchtbox_KeyPress(KeyAscii As Integer)
  2. Select Case KeyAscii
  3.  
  4.     Case Asc(" ") To Asc("z")
  5.  
  6.       strStringTyped = Me.abSearchtbox.Text & Chr(KeyAscii)
  7.  
  8.      Case 8
  9.          If strStringTyped > "" Then
  10.             strStringTyped = Left$(strStringTyped, Len(strStringTyped) - 1)
  11.         End If
  12. End Select
  13.  
  14.  
  15. CheckListbox strStringTyped, Me.allAddressBooklbox
  16.  
  17. End Sub
  18.  
I also tried another method but neither work when the multi select property is not none. I can't search at all.


Any Ideas??
Feb 15 '10 #1
3 1967
ADezii
8,834 Recognized Expert Expert
Hello xraive, I'm a little confused at to what you are trying to accomplish here. Please explain in detail, providing all relevant information.
Feb 15 '10 #2
xraive
30 New Member
Sorry Adezii,

I currently have a listbox and would like to be able to search the records. I have a textbox setup so that when the user enters a key an item matching it in the listbox would be selected. This would be similar to the autoexpand feature on the combo box. I would like to be able to have a user type in a string and the first Item matching that string be selected from the listbox. I hope I made myself a little clear. I can attach a sample db of what I am doing if you like.


Thanks for your time ADezii
Feb 15 '10 #3
ADezii
8,834 Recognized Expert Expert
This should point you in the right direction:
Expand|Select|Wrap|Line Numbers
  1. Private Sub abSearchTBox_KeyPress(KeyAscii As Integer)
  2. Dim strStringTyped As String
  3. Dim intCurrIndex As Integer
  4. Dim intStringLen As Integer
  5.  
  6. 'Clear ALL Selections with each Keystroke
  7. For intCurrIndex = 0 To allAddressBooklbox.ListCount - 1
  8.   allAddressBooklbox.Selected(intCurrIndex) = False
  9. Next
  10.  
  11. strStringTyped = Me.abSearchTBox.Text
  12.  
  13. Select Case KeyAscii
  14.   Case Asc(" ") To Asc("z")
  15.     strStringTyped = strStringTyped & Chr(KeyAscii)
  16.   Case 8
  17.     If strStringTyped <> "" Then
  18.       strStringTyped = Left$(strStringTyped, Len(strStringTyped) - 1)
  19.     End If
  20.   Case Else
  21.     KeyAscii = 0        'CANCEL the Keystroke?
  22. End Select
  23.  
  24. intStringLen = Len(strStringTyped)
  25.  
  26. For intCurrIndex = 0 To allAddressBooklbox.ListCount - 1
  27.   If Left$(allAddressBooklbox.ItemData(intCurrIndex), intStringLen) = strStringTyped Then
  28.     allAddressBooklbox.Selected(intCurrIndex) = True
  29.       Exit For
  30.   End If
  31. Next intCurrIndex
  32. End Sub
  33.  
Feb 15 '10 #4

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

Similar topics

0
1820
by: Colleyville Alan | last post by:
I have an app that looks up an id number and when a button is clicked, inputs the id # into a query. After running the query, I click a second button which grabs the client name rather than the id for input to another operation. Originally, I had a drop-down box with the client name and the client id number and it worked fine, but it was for a demo and was quick-and-dirty. For the real app, there are over 1,700 client ids and the...
1
5034
by: Alvey Sidecast | last post by:
This is probably embarrassingly simple, but I've been trawling through this ng for hours now and my brain hurts. I've got an unbound multi-column listbox (multi-select=none) whose rowsource is a query based on a combobox selection. After the selection is made from the combobox the listbox may, or may not, have records in it. If it doesn't, no problems, I've got; If Me.lbxContacts.ItemsSelected.Count = 0 Then
2
3677
by: Simon P | last post by:
Hello group, I'm in desperate need of help. Here goes : I have the following tables : CONTACTS (ContactID, FirstName, LastName, Company, etc.), SHOWS (ShowID, ShowDescription) and SHOWDETAILS (links the previous tables together so not to have a many-to-many relationship -- has the ContactID and ShowID fields). I have a main form with a couple of listboxes which are used for querying the CONTACTS table. The results populate bound fields...
3
3433
by: Colleyville Alan | last post by:
I have a incremental search box that has been working fine for a couple of months but is now acting up. This search box is from the cd that comes with Getz's book, so I did not write it and have only a superficial understanding of how it works. I have had some trouble in the past when my code goes to another form and comes back sometimes the search function did not work properly. Then I added a line to requery it and it worked fine. ...
2
6075
by: Alan Lane | last post by:
Hello world: I'm using Access 2003. I have 2 listboxes. One is a single column. The other has two columns. I can use Dev Ashish's code (thanks Dev!) from the Access MVP Website to accumulate the values from the bound column of a MultiSelect listbox, so that I can include them in a SQL query that will then be the recordsource for a report. This gives me 2 of the 3 values I need to put into the SQL query. However, I can't get the non...
5
16448
by: RBohannon | last post by:
I have a multi-selectable listbox named lstTitles. In the OnClick event I had the following: If Not IsNull(Me.lstTitles) Then ' do something with list selection Else ' do something else End If This worked when I wrote it and has continued to work since...until
32
14881
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
8
3522
by: tshad | last post by:
I cannot seem to get the asp:textbox to use classes. Style works fine. I am trying to set the textbox to act like a label in some instance so it doesn't have a border, readonly and the background is grey. I have a class set as: ..table2Label{ border-style:none; background-color:#F6F6F6; }
5
4084
by: Matthew Wells | last post by:
I have a listbox set to simple multi select. For this example, users only select one item at a time. I have command buttons on the form for First, Previous, Next, Last, New (record). The form and listbox are unbound. The listbox rowsource is a value list. The list box has about sixty items in it. Each item in the list box corresponds to a record in the database. When a user selects a row in the list box, the record is retrieved. The...
3
3627
by: kaosyeti via AccessMonster.com | last post by:
hey... i have an unbound multiselect listbox on a form that i want to use to populate text boxes on that form. so if a user selects the 3rd item in a list of 20, how can i have that item show up in a text box? then, how can i have a second selected item show up in a different text box, without affecting the 1st one? (lboxOptions, txtboxOptions0, txtboxOptions1, etc..) -- Greg Message posted via AccessMonster.com
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.