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
15 49438
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")
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?
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?
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");
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!
the second method seems to work, try it.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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.
|
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.
|
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
|
by: sreekalavinu |
last post by:
I wish to include a search engine within my website.please give your thoughts
| |
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
|
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,
|
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...
|
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;
----------------------------------------
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |