473,386 Members | 1,819 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,386 software developers and data experts.

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

30
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 1959
ADezii
8,834 Expert 8TB
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
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 Expert 8TB
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
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...
1
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...
2
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...
3
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...
2
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...
5
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...
32
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...
8
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...
5
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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...

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.