473,769 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search Record Within a ListBox

6 New Member
Hi I am new to MS Access and VBA and have been bothered by this problem for a looooong time. I have this listbox containing all the records (~1000) in a form and I want to be able to type something in and match it with the matching record IN the listbox. I want it to work exactly like the "Find" function in the "Edit" Menu on the Toolbar, however the Find function does not search anything within the listbox.

I tried tp create a textbox and its name is "SearchBox" with a command button called "cmdSearch" . I have the following code on the clicking event of the command button but it says Error:

Private Sub cmdGoSearch_Cli ck()

Dim SearchString As String

SearchString = Me.SearchBox.Va lue
ComputerList.Se tFocus

DoCmd.FindRecor d SearchString, , , , , acAll, True


End Sub

Is there just a syntax error or I have to use some other command or there is no way to implement a Find function like I desire in a listbox?

I have to use a listbox because the desired outlook of the interface is like viewing files in "Details" view of a normal window. I thought about using a form and aligning it nicely but it just won't give you something like a listbox. Using a subform in datasheet view is not desired either.


Please shed me some light on that. Thank you soooooooooooooo much!


allansiu823
Jul 31 '06 #1
15 49438
nova_lite
9 New Member
Try this, im new to access and vba too tho so no idea if it will work..

ListBox1.Select edIndex = ListBox1.FindSt ring("SearchStr ing")
Jul 31 '06 #2
allansiu823
6 New Member
Try this, im new to access and vba too tho so no idea if it will work..

ListBox1.Select edIndex = ListBox1.FindSt ring("SearchStr ing")

It seems okay but there is no "FindString " method.......an y similar methods though?
Jul 31 '06 #3
nova_lite
9 New Member
try FindByValue
Jul 31 '06 #4
allansiu823
6 New Member
Doesnt work either.

I think the problem is the data type. It seems like the listbox does not have those function because when I type ListBox1. and search through the options in the pop up list I cannot find anything related to "find" (nor FindString and FindByValue). Would this be because a listbox simply just doesnt support these find functions? Is there another way to display the records like a listbox then?
Jul 31 '06 #5
nova_lite
9 New Member
http://msdn.microsoft.com/library/de...tringTopic.asp

there is a FindString method for listboxes, I don't know if it is for access tho.
Jul 31 '06 #6
nova_lite
9 New Member
Try this:

If the items contained within your ListBox are just strings then you could use the IndexOf() method to search the items for a specific string and then set the ListBox’s SelectedIndex property to the value gained from IndexOf() ala:

// Find the item in the list and store the index to the item.
int index = listBoxPartInfo ..Items.IndexOf (searchString);
// Determine if a valid index is returned. Select the item if it is valid.
if (index != -1)
listBoxPartInfo .SelectedIndex = index;
else
MessageBox.Show ("The search string did not match any items in the ListBox");
Jul 31 '06 #7
nova_lite
9 New Member
Or this lol.. sorry im just shooting you things I found from other forums..

From time to time, I am frequently asked this question – How do I search a listbox for a string? Well you need ask now more!


Code:
Option Explicit
Private Declare Function SendMessage Lib "User32" Alias "SendMessag eA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long

'Searchs a listbox for a matching string. Returns the listindex of the matching item.

Function ListboxFindStri ng(strSearchStr ing As String, lHwndListbox As Long) As Long
Const LB_FINDSTRING = &H18F
ListboxFindStri ng = SendMessage(lHw ndListbox , LB_FINDSTRING, -1, ByVal strSearchString )
End Function



Code:
Private Sub Text1_Change()
Me.List1.ListIn dex = ListboxFindStri ng(Me.Text1, Me.List1.hWnd)
End Sub

Private Sub Form_Load()
With List1
.AddItem "Haresoftwa re"
.AddItem "LocateSoft "
.AddItem "EncodeSoft "
.AddItem "IconSoft"

End With
End Sub


Hey Presto! Search a ListBox for a string!
Jul 31 '06 #8
nova_lite
9 New Member
the second method seems to work, try it.
Jul 31 '06 #9
nova_lite
9 New Member
http://www.vbcity.com/forums/topic.asp?tid=64808

heres more on that..
Jul 31 '06 #10

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

Similar topics

1
6679
by: Geir Baardsen | last post by:
Hi! On frmItems I have a two listboxes. The first, lstAllCategories, is loaded with data from tblCategory when frmItems open. When user click lstAllCategories, the lstSelectedItems will show all records for that category. Now when user clicks chosen item in lstSelectedItems, textboxes in form will be filled and now user can edit the selected item.
2
2374
by: Geir Baardsen | last post by:
Hi! I wasn't very clear, I think... On frmItems I have a listbox, lstShowItems, that is being filled up in the forms onload event with all records from tblItems. Now when user navigate between records I did wish the cursor would jump to the actual ItemID and select it in the lstShowItems.
3
5019
by: Simon Rowe | last post by:
Probably really simple but I cant work it out... I have a list box on a form with a few records in. When I open the form the first record is sort of highlight with a dashed box, when I cursor down the record changes to inverse video and from then on I can sroll up and down the records with the inverse video highlight. I just cant seem to get the form to open with the first record already highlighted in inverse video.
0
1311
by: Robert Karlsson | last post by:
Hi, Is there a way of generating a tab within a ListBox item to create the illusion of columns within the item? Example: Header 1 Header 2 <- labels -------------------------------------------- |Blablabla Blabllaaa | <- item 0
5
26293
by: sreekalavinu | last post by:
I wish to include a search engine within my website.please give your thoughts
4
4001
by: Steven | last post by:
Hi, Would need some thought about using a button of the existing form to search record before deleting it. Any quick help is very appreciated. Steve
7
1960
stonward
by: stonward | last post by:
Hi, I'm (now) a moderately experienced Access developer, but I'm currently stuck with a problem i can't seem to get over. I have a filtered listbox of products on a form and I want to use the selection (single select) of the listbox to start a new record in a subform below it. Can anyone help? I would be muchly grateful. Thanx folks,
1
1604
by: David De | last post by:
Need help with my site - search function within my site not working?!? I purchased this template, customized it and found out it has a search function for within the site - the challenge is that SEARCH function is a dummy text box and doesn't work (apparently I have to pay much more to get it to work). I want to get it to work, but I am unsure how to do it on my own, hopefully nothing too complicated. The banner is in FLASH, so I am...
1
4778
by: Rohullah | last post by:
hello i am new with oracle form 6i, I want to search record in oracle form6i i am using this code but i dont know it is not working what is the reason. --------------------------------------- select empno,ename,job,mgr,hiredate,sal,comm,deptno into:emp.empno,:emp.ename,:emp.job,:emp.mgr,:emp.hiredate,:emp.sal,:emp.comm,:emp.deptno from emp where empno=:block4.search1; ----------------------------------------
0
9422
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
10208
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
9857
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7404
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
5294
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
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.