473,662 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

move to a particular record in a list box?

Hi all,

I have a list box that is populated with enough records such that
there are scroll bars and a user will have to scroll through the box
to see all of the records.

I want to add functionality that does the following:
the user types a few letters (like "th") into a text box and clicks a
button and the list box moves down to that row.

Code would look something like this:
("ctlList" is the list box, "SearchSessions box" is the search text
box)

For intCurrentRow = 0 To ctlList.ListCou nt - 1
If ctlList.Column( 1, intCurrentRow) Like
(CStr(Me.Search Sessionsbox) & "*") Then
' NEED CODE HERE TO MAKE THE LIST BOX JUMP TO THAT ENTRY
' maybe something like this:
ctlList.SetFocu s (intCurrentRow)
End If
Next intCurrentRow

The problem with that code is SetFocus() doesn't take any parms.

Anyone know how I can do this?

Thanks in advance,
Jon
Nov 12 '05 #1
8 6648
> I want to add functionality that does the following:
the user types a few letters (like "th") into a text box and clicks a
button and the list box moves down to that row.


You might try a query, a function, and a recordset. I know this works with
a datasheet, not sure about list...

The query would look something like this:

SELECT MyField, Record_ID
FROM tblMyTable WHERE ( MyString Like QryPrm("MyForm" ,"MyTxtBox") );

The function:

Public Function QryPrm(ByVal strFrm As String, ByVal strCtl As String)
As Variant
QryPrm = Forms(strFrm).C ontrols(strCtl)
End Function

The recordset:

Dim lngId As Long
Dim rst As DAO.Recordset
lngId = Nz(DLookup("Rec ord_ID", "qryMyQry") , 0)
Set rst = Me.RecordsetClo ne
rst.FindFirst "[Record_ID] = " & lngId
If rst.NoMatch Then MsgBox "No matching records"
Me.Form.Bookmar k = rst.Bookmark
Nov 12 '05 #2
Hi Jonathan,

Not trying to be a "smart-ass" ... but isn't that what a combo-box does ...
without the need for a seperate textbox...?
Let me qualify that ... a combobox with it's AutoExpand Property set to True
(which is the default) will do that..

Don
"Jonathan LaRosa" <jl*****@alumni .brown.edu> wrote in message
news:e6******** *************** ***@posting.goo gle.com...
Hi all,

I have a list box that is populated with enough records such that
there are scroll bars and a user will have to scroll through the box
to see all of the records.

I want to add functionality that does the following:
the user types a few letters (like "th") into a text box and clicks a
button and the list box moves down to that row.

Code would look something like this:
("ctlList" is the list box, "SearchSessions box" is the search text
box)

For intCurrentRow = 0 To ctlList.ListCou nt - 1
If ctlList.Column( 1, intCurrentRow) Like
(CStr(Me.Search Sessionsbox) & "*") Then
' NEED CODE HERE TO MAKE THE LIST BOX JUMP TO THAT ENTRY
' maybe something like this:
ctlList.SetFocu s (intCurrentRow)
End If
Next intCurrentRow

The problem with that code is SetFocus() doesn't take any parms.

Anyone know how I can do this?

Thanks in advance,
Jon

Nov 12 '05 #3
> Not trying to be a "smart-ass" ... but isn't that what a combo-box does ...
without the need for a seperate textbox...?
Let me qualify that ... a combobox with it's AutoExpand Property set to True
(which is the default) will do that..


yes, this is what a combo box does. except there is a requirement
that i did not mention that forces the use of a list box - the ability
to select multiple values. which means the combo box idea is out.

thanks,
jon
Nov 12 '05 #4
jl*****@alumni. brown.edu (Jonathan LaRosa) wrote in message news:<e6******* *************** ****@posting.go ogle.com>...
Hi all,

I have a list box that is populated with enough records such that
there are scroll bars and a user will have to scroll through the box
to see all of the records.

I want to add functionality that does the following:
the user types a few letters (like "th") into a text box and clicks a
button and the list box moves down to that row.

Code would look something like this:
("ctlList" is the list box, "SearchSessions box" is the search text
box)

For intCurrentRow = 0 To ctlList.ListCou nt - 1
If ctlList.Column( 1, intCurrentRow) Like
(CStr(Me.Search Sessionsbox) & "*") Then
' NEED CODE HERE TO MAKE THE LIST BOX JUMP TO THAT ENTRY
' maybe something like this:
ctlList.SetFocu s (intCurrentRow)
End If
Next intCurrentRow


Setting ctlList.Selecte d(intCurrentRow ) = True will scroll to and
select that item in the list.

Bruce
Nov 12 '05 #5
Hi Jon,

I don't think Bruce's method will do what he thinks it will ... but I could
be wrong ... go ahead and try.

I think it will indeed "select" the first row that it fits the criteria, but
I doubt that it will scroll to it? AFAIK, there is no way to automatically
scroll to the desired row.

Now I'm thinking that you may be able to limit the number of rows that do
get displayed in the list, and eliminate (or at least reduce) the need for
scrolling .

This could be done by building an SQL string in code, and then using that
SQL as the Row Source for the listbox.

Try this, and see if it suits your needs...
(You will have to edit Table, Field, and Control Names ... )

*************** *************** *************
Private Sub cmdRequeryListb ox_Click()

Dim strFilter
Dim MySQL As String
Dim whr As String

strFilter = Me.txtFilter

MySQL = ""
MySQL = MySQL & "SELECT YourTableName.Y ourFieldName FROM YourTableName "

whr = ""
If Len(strFilter) > 0 Then 'If the user has typed something to narrow
the search

whr = whr & "WHERE (((YourTableNam e.YourFieldName ) Like "

'There are two ways to go here ... "Contains" OR "Begins With"
'eg "*pat*" would give you "Patrick Fitzsimons" AND "Simon Fitzatrick"
' or "pat*" would return "Patrick Fitzsimons" only
'--- this example is for "Contains ---"

whr = whr & " '*' "
whr = whr & " & "
whr = whr & Chr$(34) & strFilter & Chr$(34)
whr = whr & " & "
whr = whr & " '*' "
whr = whr & "))"

MySQL = MySQL & whr 'Insert the WHERE into the SQL string

End If

MySQL = MySQL & ";"
'Debug.Print MySQL

Me.lstFiltered. RowSource = MySQL

End Sub
*************** *************** *************

HTH,
Don

Jonathan LaRosa <jl*****@alumni .brown.edu> wrote in message
news:e6******** *************** ***@posting.goo gle.com...
Not trying to be a "smart-ass" ... but isn't that what a combo-box does .... without the need for a seperate textbox...?
Let me qualify that ... a combobox with it's AutoExpand Property set to True (which is the default) will do that..


yes, this is what a combo box does. except there is a requirement
that i did not mention that forces the use of a list box - the ability
to select multiple values. which means the combo box idea is out.

thanks,
jon

Nov 12 '05 #6
Don you can use the ListIndex property to simulate the standard ListBox
TopIndex property.

http://www.lebans.com/List_Combo.htm#ScrollListbox
Scroll a ListBox to a specific row. Emulates the VB ListBox TopIndex
property. You can alter the code to easily have the selected row display
as the first or last row as well. The example code is placed behind a
Command Button.

' *** CODE START
Private Sub cmdListIndex_Cl ick()
On Error GoTo Err_cmdListInde x_Click

' Always make NumRows an odd number
' if you want selected Row to be in the
' middle of the ListBox.

' NumRows is the number of completely visible rows in the ListBox Const
NumRows = 7
' Row we want displayed in middle of ListBox.
Dim intDesiredRow As Integer

' Arbitrarily select the 24th row.
intDesiredRow = 24
' ListBox must have the Focus
Me.List2.SetFoc us
' Force ListBox to start from the top
Me.List2.ListIn dex = 1

' Force the Scroll offset we desire
Me.List2.ListIn dex = intDesiredRow + (NumRows / 2)
' Now select the row without further scrolling
Me.List2.ListIn dex = intDesiredRow

Exit_cmdListInd ex_Click:
Exit Sub

Err_cmdListInde x_Click:
MsgBox Err.Description
Resume Exit_cmdListInd ex_Click

End Sub
' ***CODE END


--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Don Leverton" <My*****@Telus. Net> wrote in message
news:%XTmc.6040 $uN4.2535@clgrp s12...
Hi Jon,

I don't think Bruce's method will do what he thinks it will ... but I could be wrong ... go ahead and try.

I think it will indeed "select" the first row that it fits the criteria, but I doubt that it will scroll to it? AFAIK, there is no way to automatically scroll to the desired row.

Now I'm thinking that you may be able to limit the number of rows that do get displayed in the list, and eliminate (or at least reduce) the need for scrolling .

This could be done by building an SQL string in code, and then using that SQL as the Row Source for the listbox.

Try this, and see if it suits your needs...
(You will have to edit Table, Field, and Control Names ... )

*************** *************** *************
Private Sub cmdRequeryListb ox_Click()

Dim strFilter
Dim MySQL As String
Dim whr As String

strFilter = Me.txtFilter

MySQL = ""
MySQL = MySQL & "SELECT YourTableName.Y ourFieldName FROM YourTableName "
whr = ""
If Len(strFilter) > 0 Then 'If the user has typed something to narrow the search

whr = whr & "WHERE (((YourTableNam e.YourFieldName ) Like "

'There are two ways to go here ... "Contains" OR "Begins With"
'eg "*pat*" would give you "Patrick Fitzsimons" AND "Simon Fitzatrick" ' or "pat*" would return "Patrick Fitzsimons" only
'--- this example is for "Contains ---"

whr = whr & " '*' "
whr = whr & " & "
whr = whr & Chr$(34) & strFilter & Chr$(34)
whr = whr & " & "
whr = whr & " '*' "
whr = whr & "))"

MySQL = MySQL & whr 'Insert the WHERE into the SQL string

End If

MySQL = MySQL & ";"
'Debug.Print MySQL

Me.lstFiltered. RowSource = MySQL

End Sub
*************** *************** *************

HTH,
Don

Jonathan LaRosa <jl*****@alumni .brown.edu> wrote in message
news:e6******** *************** ***@posting.goo gle.com...
Not trying to be a "smart-ass" ... but isn't that what a combo-box
does
... without the need for a seperate textbox...?
Let me qualify that ... a combobox with it's AutoExpand Property
set to
True (which is the default) will do that..


yes, this is what a combo box does. except there is a requirement
that i did not mention that forces the use of a list box - the ability to select multiple values. which means the combo box idea is out.

thanks,
jon



Nov 12 '05 #7
"Don Leverton" <My*****@Telus. Net> wrote in message news:<%XTmc.604 0$uN4.2535@clgr ps12>...
Hi Jon,

I don't think Bruce's method will do what he thinks it will ... but I could
be wrong ... go ahead and try.

I think it will indeed "select" the first row that it fits the criteria, but
I doubt that it will scroll to it? AFAIK, there is no way to automatically
scroll to the desired row.


It's not a matter of me 'thinking' it will, it's a matter of me having
tested it and demonstrated that it will, else I would not have posted
it without the caveat "I think this should work..." . I did not test
it with a multiselect listbox, however, but I _think_ that should work
as well :) There could definitely be situations in which the listbox
could not display all of the selected items simultaneously however. I
think Don's solution in which one limits the actual display of items
in the listbox to those which meet your criteria is preferred where
multiple items need to be selected.

Bruce
Nov 12 '05 #8
Hi Bruce,

I'm sorry, I meant no offence.

In fact I was attempting to be polite, because I had already tried something
almost identical to what you had posted, and found that while the row was
indeed "selected", it was still out of view.

*************** *************** *************** **
Private Sub cmdSelectListRo w_Click()

Dim intCurrentrow As Integer

For intCurrentrow = 0 To ctlList.ListCou nt - 1

If ctlList.Column( 0, intCurrentrow) Like (CStr(Me.Search Sessionsbox) &
"*") Then
ctlList.Selecte d(intCurrentrow ) = True
Else
ctlList.Selecte d(intCurrentrow ) = False
End If

Next intCurrentrow

End Sub
*************** *************** *************** **
I thought I must have missed something, so I tried it again ... with the
same result.

Then I followed up on your comment about not trying the Multi-Select ...
When I changed my Multi-Select property from "Extended" to "None", it does
do as you say it will!
(I tried "Simple", too ... but I still see the same behaviour as "Extended")

Regards,
Don

"Bruce" <br***@aristotl e.net> wrote in message
news:d3******** *************** ***@posting.goo gle.com...
"Don Leverton" <My*****@Telus. Net> wrote in message

news:<%XTmc.604 0$uN4.2535@clgr ps12>...
Hi Jon,

I don't think Bruce's method will do what he thinks it will ... but I could be wrong ... go ahead and try.

I think it will indeed "select" the first row that it fits the criteria, but I doubt that it will scroll to it? AFAIK, there is no way to automatically scroll to the desired row.


It's not a matter of me 'thinking' it will, it's a matter of me having
tested it and demonstrated that it will, else I would not have posted
it without the caveat "I think this should work..." . I did not test
it with a multiselect listbox, however, but I _think_ that should work
as well :) There could definitely be situations in which the listbox
could not display all of the selected items simultaneously however. I
think Don's solution in which one limits the actual display of items
in the listbox to those which meet your criteria is preferred where
multiple items need to be selected.

Bruce

Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4748
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record onto the bottom of the list (even though it keeps its record number). Also, There are certin names that i click on the list, and it will not bring it up, rather it brings to the first record (no matter how many times i try going to that...
2
4622
by: Paolo | last post by:
Friends, I have created a form named FRMNEWCLIENTS whose record source is a table named NEWCLIENTS. This table has a field named FILENUMBER. I have added on the form a combobox using the third option "find a record based on my form based on the value I selected in my combobox". This is great since it allows me to open the form and use the combo to move to a selected records. My form has also two other fields named FNAME and LNAME. My...
5
24026
by: deko | last post by:
I have a subform datasheet that contains a full year of records sorted by a date field. I'm trying to programmatically move the record selector on the datasheet to the first record that matches a particular date. For example, the user clicks a button and the record selector moves to the first record that matches today's date. I was thinking something like this, but I'm not having any luck: Dim rst As DAO.Recordset Set rst =...
1
680
by: sixsoccer | last post by:
I have built a database with a <Mainform> and a <Subform>. My problem is twofold. 1. My subform is set as a continuos form with AllowAddiotions set to NO (ie. a list of Issues to the client on the mainform) 2. To add new issues, a button is used and a pop-up form is used to add an issue with more detail than what's available on the subform. 3. On accepting the new Issue from the pop-up the pop-up closes and you are returned to the...
7
2038
by: Byron | last post by:
I'm looking for a way to deny a move from the current listbox item. For instance, if the user is editing the record associated with the current listbox item I want to deny a move within the listbox until they have saved the changes. Is there any way to deny a move from the current item so the SelectedIndexChanged event never fires no matter move the movement was attempted? Whether the user uses the cursor keys or mouse to try and leave...
5
3367
lwwhite
by: lwwhite | last post by:
I'm trying to reproduce functionality I've seen in some other (non-Access) applications. On one of my forms, the master record is a document. The subform consists of a datasheet list of the topics within that document--a kind of table of contents of the document. Problem is, the records in the datasheet list are not in the same order as they are in the document; rather, they're in the order that people added them to the database. I've tried...
7
1999
by: Starke | last post by:
I have a table that contains an SCC # and then locations, Qty, SKU. As below SCC Lcoation qty Sku 123 adffa 3 321a1 m 123 adfa 3 32111 l 123 adfa 3 32111 xl 123 adfffa 3 32111 s 321 adfffa 3 32111 m 321 addfa 3 32111 d
3
2107
by: lucky13 | last post by:
Dear All, I have hundered of records in Flexgrid & find a particular record is dififcult & if i want to fiind out particulart record from second column so what i want that in one text box as i type the row which have that data move top or move up. Pls. help me. Regards Lucky13
2
1709
by: beemomo | last post by:
Hi everyone here, Wondering if this can be perform in access using SQL or vba. VesselMovement table: RNO Date_Fix TIME VID X Y HEADING SPEED 1 07/05/2009 00:00 605 5.1896 6.7198 81 0.3 2 07/05/2009 00:30 605 5.1896 6.7198 90 0.4 3 07/05/2009 01:00 605 5.1847 6.7193 0 4.0 ...
0
8343
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
8762
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
8545
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
7365
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
6185
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
4179
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...
1
2762
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
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
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.