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
15 49450 http://www.vbcity.com/forums/topic.asp?tid=64808
heres more on that..
Hey nova_lite I have tried the second method but sadly I dont quite understand the "Send Message" thing and I tried to compile that in VBA but it is not working....Trie d your code too but there just isnt a FindString method....Do you or others have other ideas? I dont know if VB and VBA are that different.....
Thanks in advance :D
Would it be okay if you email me your source? I would like to take a closer look at it.
Actually.. rather than trying to find one function, why don't you use a for loop and loop through the list. Something like this:
Private Sub cmdListIndex_Cl ick()
' NumRows is the number of completely visible rows in the ListBox
Const NumRows = 10
' Row we want displayed on top of ListBox.
Dim intDesiredRow As Integer
If txtSearch <> "" Then
'loops through the listbox
For i = 0 To Me.ListBox1.Lis tCount
'If the Strings match
If txtSearch = ListBox1.ItemDa ta Then
'Record down row found
intDesiredRow = i
'End loop
i = Me.ListBox1.Lis tCount
End If
Next i
End If
' ListBox must have the Focus
Me.ListBox1.Set Focus
' Force ListBox to start from the top
Me.ListBox1.Lis tIndex = 1
' Force the Scroll offset we desire
Me.ListBox1.Lis tIndex = intDesiredRow + (NumRows - 1)
' Now select the row without further scrolling
Me.ListBox1.Lis tIndex = intDesiredRow
End Sub
The code above should DEFINATELY work lol.. try it out
Actually.. rather than trying to find one function, why don't you use a for loop and loop through the list. Something like this:
Private Sub cmdListIndex_Cl ick()
' NumRows is the number of completely visible rows in the ListBox
Const NumRows = 10
' Row we want displayed on top of ListBox.
Dim intDesiredRow As Integer
If txtSearch <> "" Then
'loops through the listbox
For i = 0 To Me.ListBox1.Lis tCount
'If the Strings match
If txtSearch = ListBox1.ItemDa ta Then
'Record down row found
intDesiredRow = i
'End loop
i = Me.ListBox1.Lis tCount
End If
Next i
End If
' ListBox must have the Focus
Me.ListBox1.Set Focus
' Force ListBox to start from the top
Me.ListBox1.Lis tIndex = 1
' Force the Scroll offset we desire
Me.ListBox1.Lis tIndex = intDesiredRow + (NumRows - 1)
' Now select the row without further scrolling
Me.ListBox1.Lis tIndex = intDesiredRow
End Sub
The code above should DEFINATELY work lol.. try it out
Works Perfectly!
Thank you soooo much nova!!!!
I would like more on the 2nd method
which is having a text box search a listbox but for vba for access.
I know this reply is a little late (almost a year), but I was looking for a method to do a string search in a Access listbox. By the way, access listboxes are a little different than VB listboxes. Anyways, after unsuccessfully finding anything good on the internet, I decided to try and figure it out myself. Here's what I have. It works even if your listbox or has multiple columns. Here's the code:
=============== =============== =============
Dim strSearch As String
Dim i As Long
Dim iContinueSearch As Integer
strSearch = InputBox("Enter Search String")
strSearch = "*" & strSearch & "*"
With Me.lstMyListBox
If .ListCount > 0 Then
.Selected(0) = True
For i = 0 To .ListCount - 1
If .Column(3, i) Like strSearch Then
.Selected(i) = True
iContinueSearch = MsgBox("Do you want to continue searching?", vbQuestion + vbYesNo)
If iContinueSearch = vbNo Then
Exit For
End If
End If
Next i
End If
End With
=============== =============== ==============
The code above searches the contents of the listbox called lstMyListBox. There are 4 columns in the listbox and the code above searches the 4th column. You can change this by changing the .Column(#, i) where # is index of the column (0 is the base). The code above simply goes through the list from top to bottom and searches whatever column for a search string that you pass to it with the strSearch variable. I added a "*" at the beginning and end of the search string and used a like operator to conduct a wildcard search. This allows you to search the column data for anything that contains your search string. The code also prompts you if you want to continue searching for the next match until it reaches the end of the list and no more matches are found and the search will end.
Hope this helps.
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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,...
|
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: 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...
|
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.
| |