Scroll to specific list box entry

I am trying to scroll to a specific line entry in a multi-select list box in 
response to a user-input search criterion (in a separate text box) so that 
the desired record becomes visible to the user.  I can locate the matching 
record and determine the line number, but I can't find a VBA method to scroll 
to reposition the record.  

My intent is to enable a user to enter the beginning character(s) to locate 
the section of entries that begin with the user search criterion.  From that 
position, the user can then select the entries of choice.

I will appreciate any help.

Richard
0
Utf
4/13/2007 1:30:02 AM
access.forms 6864 articles. 2 followers. Follow

2 Replies
3807 Views

Similar Articles

[PageSpeed] 2

Here are two methods:

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_Click()
On Error GoTo Err_cmdListIndex_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.SetFocus
' Force ListBox to start from the top
Me.List2.ListIndex = 1

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

Exit_cmdListIndex_Click:
    Exit Sub

Err_cmdListIndex_Click:
    MsgBox Err.Description
    Resume Exit_cmdListIndex_Click

End Sub
' ***CODE END


Method #2

Here's the code to force a ListBox to Scroll to a specific row. I put it 
behind a Command Button Named Customer, you can obviously do
whatever you want. Really should be a Class Wrapper for a ListBox to expose 
a TopIndex property like VB ListBoxes.

' ***CODE START
'Place this code in the General Declarations of your Form
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ 
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Private Declare Function GetFocus Lib "user32" () As Long

' Windows Message Constant
Private Const WM_VSCROLL = &H115
' Scroll Bar Commands
Private Const SB_THUMBPOSITION = 4
' Code end for General Declarations


' Code for Control's Click Event
Private Sub Customer_Click()

Dim hWndSB As Long
Dim lngRet As Long
Dim lngIndex As Long
Dim LngThumb As Long

' You will get lngIndex value from the user or whatever.
' For now I'm just setting it to arbitrary Number
lngIndex = 45

' SetFocus to our listBox so that we can
' get its hWnd
Me.List2.SetFocus
hWndSB = GetFocus

' Set the window's ScrollBar position
LngThumb = MakeDWord(SB_THUMBPOSITION, CInt(LngIndex))
lngRet = SendMessage(hWndSB, WM_VSCROLL, LngThumb, 0&)

End Sub

' Here's the MakeDWord function from the MS KB
Function MakeDWord(loword As Integer, hiword As Integer) As Long MakeDWord = 
(hiword * &H10000) Or (loword And &HFFFF&) End Function '***END CODE



-- 

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


"Richard S." <RichardS@discussions.microsoft.com> wrote in message 
news:4BF734F1-1F14-4A80-AA4A-BAC7163CA830@microsoft.com...
>I am trying to scroll to a specific line entry in a multi-select list box 
>in
> response to a user-input search criterion (in a separate text box) so that
> the desired record becomes visible to the user.  I can locate the matching
> record and determine the line number, but I can't find a VBA method to 
> scroll
> to reposition the record.
>
> My intent is to enable a user to enter the beginning character(s) to 
> locate
> the section of entries that begin with the user search criterion.  From 
> that
> position, the user can then select the entries of choice.
>
> I will appreciate any help.
>
> Richard 


0
Stephen
4/13/2007 1:40:37 AM
Thank you, Stephen, for your very prompt response.  Your response resolved my 
question.  It was very clear, specific, and thorough.  Thanks again.  

"Stephen Lebans" wrote:

> Here are two methods:
> 
> 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_Click()
> On Error GoTo Err_cmdListIndex_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.SetFocus
> ' Force ListBox to start from the top
> Me.List2.ListIndex = 1
> 
> ' Force the Scroll offset we desire
> Me.List2.ListIndex = intDesiredRow + (NumRows / 2)
> ' Now select the row without further scrolling
> Me.List2.ListIndex = intDesiredRow
> 
> Exit_cmdListIndex_Click:
>     Exit Sub
> 
> Err_cmdListIndex_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdListIndex_Click
> 
> End Sub
> ' ***CODE END
> 
> 
> Method #2
> 
> Here's the code to force a ListBox to Scroll to a specific row. I put it 
> behind a Command Button Named Customer, you can obviously do
> whatever you want. Really should be a Class Wrapper for a ListBox to expose 
> a TopIndex property like VB ListBoxes.
> 
> ' ***CODE START
> 'Place this code in the General Declarations of your Form
> Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ 
> (ByVal hWnd As Long, ByVal wMsg As Long, _
> ByVal wParam As Long, lParam As Any) As Long
> 
> Private Declare Function GetFocus Lib "user32" () As Long
> 
> ' Windows Message Constant
> Private Const WM_VSCROLL = &H115
> ' Scroll Bar Commands
> Private Const SB_THUMBPOSITION = 4
> ' Code end for General Declarations
> 
> 
> ' Code for Control's Click Event
> Private Sub Customer_Click()
> 
> Dim hWndSB As Long
> Dim lngRet As Long
> Dim lngIndex As Long
> Dim LngThumb As Long
> 
> ' You will get lngIndex value from the user or whatever.
> ' For now I'm just setting it to arbitrary Number
> lngIndex = 45
> 
> ' SetFocus to our listBox so that we can
> ' get its hWnd
> Me.List2.SetFocus
> hWndSB = GetFocus
> 
> ' Set the window's ScrollBar position
> LngThumb = MakeDWord(SB_THUMBPOSITION, CInt(LngIndex))
> lngRet = SendMessage(hWndSB, WM_VSCROLL, LngThumb, 0&)
> 
> End Sub
> 
> ' Here's the MakeDWord function from the MS KB
> Function MakeDWord(loword As Integer, hiword As Integer) As Long MakeDWord = 
> (hiword * &H10000) Or (loword And &HFFFF&) End Function '***END CODE
> 
> 
> 
> -- 
> 
> HTH
> Stephen Lebans
> http://www.lebans.com
> Access Code, Tips and Tricks
> Please respond only to the newsgroups so everyone can benefit.
> 
> 
> "Richard S." <RichardS@discussions.microsoft.com> wrote in message 
> news:4BF734F1-1F14-4A80-AA4A-BAC7163CA830@microsoft.com...
> >I am trying to scroll to a specific line entry in a multi-select list box 
> >in
> > response to a user-input search criterion (in a separate text box) so that
> > the desired record becomes visible to the user.  I can locate the matching
> > record and determine the line number, but I can't find a VBA method to 
> > scroll
> > to reposition the record.
> >
> > My intent is to enable a user to enter the beginning character(s) to 
> > locate
> > the section of entries that begin with the user search criterion.  From 
> > that
> > position, the user can then select the entries of choice.
> >
> > I will appreciate any help.
> >
> > Richard 
> 
> 
> 
0
Utf
4/13/2007 1:40:01 PM
Reply:

Similar Artilces:

Searching for specific Geophysics visual basic code
Hello: Time ago I have the opportunity to see an Excel sheet that implemented an algorithm for automatic processing and interpretation of Schlumberger sounding curves in 1 dimension (EVS). a difficult geophysics calculus, because it use superior maths, but it works very very well. I really would appreciate if anybody have a similar sheet and likes to send me a copy, or, if has some code that can let me write a similar one. Any idea will be useful. Thanks very much, My best regards. Roberto Have you tried a Google search? I used the search term "Schlumberger Excel" and got ...

Putting database data into a combo box...
Hi guys, I have a working databse query thar returns a list of names. I want to put this into a combo box. Currently I am inserting the database data into a range on my spreadsheet (A1) and it uses as many rows as there are names. In my combo box properties I can specify the ListFillRange as A1:A5 or whatever and this works okay, but the thing is, as names are added to the database, I want the range A1:A5 to update dynamically. Q1. Can I send the QueryTable data directly to the combo box ListFillRange... With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=ComboBox1.Lis...

Permissions on Exchange 2000 distribution lists
How do we stop external mail being sent to a distribution list. We have a list setup with all email accounts in it for the organisation and it has been spamed recently. Is there a permission we can set to stop external mail from getting to it. We have setup in the exchange admin console to only receive emials from the distribution name. Is that enough and will it stop external emails getting to the list or will it stop all external mail going to people who's names are on the list. thanks -- Kath From Exchange General tab of the DL set it to accept msgs from authenticated users...

Contact List question
I have a user that when typing in a name to be resolved by outlook for a new email, her contact list produces two listing for that person with two different addresses. I have search all her contacts and her computer, there is only one record of the email address on file, where is the second address coming from? On Thu, 21 Sep 2006 12:33:03 -0700, ghutnick <ghutnick@discussions.microsoft.com> wrote: >I have a user that when typing in a name to be resolved by outlook for a new >email, her contact list produces two listing for that person with two >different addresses. I ...

Multiple Prompt CryptoAPI Private Key Dialog Box
Hi there... I have problem implement the S/MIME + PKI while integrating with Ms Outlook or Outlook Express...Generation the certificate I don't have any problem but when Ms Outlook prompt the CryptoAPI Private Key it will ask one time only...If I want the dialog box appear again I have to close and open back Ms Outlook then the popup dialog asking enter the CryptoAPI Private Key. Is there any solution I have to make Ms Outlook prompt dialog many times when I try to send email ? Any solution ? Thanks ...

BOM View lookup should only list items with BOMs.
The current BOM VIew Inquiry lookup lists every single item in the item master table. This is awkward & unecessary. The list would be shorter and more user friendly if it only listed the items that actually do have BOMs. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message ...

SMTP Emails not arriving in users mail box
Hello, I have a puzzeling problem! I have a user that has worked here for sometime. He has an address john@domain.com. Now for some reason external people that used to send him mail everyday or quite often has stopped going to him, the mail has stopped comming through to him and is being redirected to the administrator (as setup to do so in Exchange when it can't find the user). In his email addresses screen it is definatly in there as an SMTP address. When I send a test to this address from my hotmail account, the mail comes through to him!! I have checked with a number of the ...

Create Modeless Dialog Boxes Query?
Hi Experts I have an SDI explorer type application with a tree view and a list view. In the listview i show the thumbnails of all the bmp files in a specific folder. Now when the user double clicks on any thumbnail i want to dynamically create a modeless dialog box. Now is it possible to specify the width & height of the modeless dialog box at the time of creation, say i want the dialog box to be of the size (400,300). If this is possible how can this b dun? Waiting for comments Regards mathu mathu, See below "Snav" <davinder_76@rediffmail.com> skrev i meddelandet ...

Find duplicate, save in a list, delete duplicate using macro
Hello. I need to find a duplicate from ID col and if found, it needs to look at the data in the associated row to compare if it is truly a duplicate. And if it is (same Product and Acct #), the true duplicate will be the one with later date. Then the duplicate that has the later date record will store this info in a separate worksheet or area and then delete the dupicate from the orginal list. Can this be done by using macro? Thank you for your help in advance. For Example: ID Date Product Acct # 1150 7/24/2009 102 53 888 12/30/2009 Gas 50 1150 11/4/2009 102 53 5524...

If check box changes
Access 2003 On my subform I have 3 checkboxes format Yes\No BBAll - control source BBAll default Yes BB1 - control source BB1 default No BB2 - control source BB2 default No and 2 textboxes TextBB1 - control source =DLookUp("[BB1]","[t000Facts]","[UnitID] =" & [UnitNo]) TextBB2 - control source =DLookUp("[BB2]","[t000Facts]","[UnitID] =" & [UnitNo]) If TextBB1 is null then BB1.enabled=false If TextBB2 is null then BB2.enabled=false this means if TextBB1 is empty then the BB1 checkbox selection is disabled(s...

Color-filled boxes, borders aren't visiable on screen only in prev
We have Microsoft Office Small Business Edition 2003 on the computers at work. A coworker and I collaborate on a newsletter via our shared documents folder on the server. For no obvious reason, when she was working on the newsletter in Publisher today, none of the color fills, transparencies or text box borders would show up on the screen. The Format text box tabs show what she did and the changes are visiable in the print preview window, but not on screen when actually working in the document. The same document works fine and shows everything when I pull it up on my computer. I made s...

Click Boxes for each series in a graph
I have a chart with three series over time. Lets say the range is C2:Z5. The time is expressed in row 2 and the series data in rows 3,4,5. I want to be able to turn the series on with click boxes. I have the graph set up on a worksheet so that some of the cells of the worksheet are visible. I want to avoid VBA code (for now). So I would like to set up checkboxes on the spreadsheet itself (if possible). I want to be able to click the checkbox for each series. When checkbox is click series is visible when not clicked series not visible. Any ideas on how to do this? Thanks. Hi ...

Drop dow list complication
In cell A1 I have a drop down list with 15 options. I have 15 seperate named lists which correspond to the options in the first list. In cell B1, I want another dropdown list which corresponds to the option chosen in A1. Using nested if statements in the B1 "list source" window, I can only get up to 7 corresponding lists. I tried using a vlookup, but the value is not recognized as a Name, therefore it is invalid as a list source. Is there any way around this? This might help http://www.contextures.com/xlDataVal02.html Regards, peo Sjoblom "Ryan" wrote: > I...

address list that always has every user in it
Does anyone know of a way to create an address list that will always contain all of the users? Thanks, Scott ...

Email Lists in Excel
Is there a way that I can create a variable Email listing in Excel, Word, or Outlook (Like a distribution form) that I can control who gets the email by checking or uncheck a box? ...

Global Address List Outlook 2000
Question: When I start Outlook 2000 I get a message saying "The server containing the global address list is no longer available". Does anyone know how I could go about fixing this problem? Thanks. J. What scenario are using Outlook in? Desktop computer at work? Laptop that you connect and disconnect from an Exchange Server? Sounds like you used to be connecting to an exchange server but now have moved away from your original connection. Tools | Services allows you to change the connection settings of your account. "Jimmy Outlook" <JimmyOutlook@discussions.microsof...

distribution lists #18
This is a multi-part message in MIME format. ------=_NextPart_000_0006_01C6C11D.0A99C5E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I was wondering the best way to create distribution lists. I've noticed = two different areas, active directory, and then again in groups under = system manager for exchange. The distribution lists I create in the = active directory show up in the global address list, however the groups = show up only in the groups list in the address list.=20 I am running exchange 2003 sp1. I ask because I accidenta...

how to print the contents of a list control?
hi all, can any one help me to print the contents of a list control in the the same format they appear in the list control . thanks and regards Here's an article that might help you... Tom http://www.codeproject.com/listctrl/listprint.asp "Manikandan" <manikandan_r@hotmail.com> wrote in message news:udsmqhioFHA.708@TK2MSFTNGP09.phx.gbl... > hi all, > > can any one help me to print the contents of a list control > in the the same format they appear in the list control . > > thanks and regards > ...

How do I time/date stamp an entry in a note from a calendar entry?
Using Outlook 2003. I have calendar entry "Call so and so...." I have called this person before and want to time date this call above the other one. I can enter it manually however other programs I have used wil do this automatically. Surely Outlook can do this? in outlook 2003 you need to use a utility or enter it manually. You can also use VBA to do it. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by email: mailto:dailytips-subscribe-request@lists.out...

Viewing ALL text entry for a cell
I have a spreadsheet which has a cell with long written descriptions for item entries in each row. Some descriptions are pretty lengthy and the cell seems to cut off the text entry once it's reached a particular length. How can I have the cell display the full text entry? I've got the cell formatted to wrap text and seems to do fine, until you reach a certain lenth (character count)??? Is there a max character count in the cells? If so, can that be changed?? I am using Excel 2000. --- Message posted from http://www.ExcelForum.com/ from Excel XP help - Length of cell contents...

Listed Option quotes.
I have several listed puts that were correctly downloaded from Schwab but the quotes are not correct. Check LQDXH for example. Money reports last price of $2.55 but the actual price quote is $6.90. Hank In microsoft.public.money, Pee2 wrote: >I have several listed puts that were correctly downloaded from Schwab but >the quotes are not correct. Check LQDXH for example. Money reports last >price of $2.55 but the actual price quote is $6.90. Hank > In Money the symbol will have to be entered as .LQDXH including the leading period. However this will conflict with the symb...

exchange rate on journal entry #2
I ran into a strange situation today. My exchange rates are defined to pick the next exchange rate if the rates for the transaction dates are not defined. I have exchange rate defined as 1.1 for the period of 1/1/06 with expiration date of 1/7/06 and 1.2 for 1/8/06 with expiration date of 1/14/06. When I enter a journal entry for the date of 1/2/06, I expect the rate to be picked up will be 1.1 but the rate picked up is 1.2. If I enter a journal entry for the date of 1/1/06, the rate picked up is 1.1. can anyone explain? ...

How do i have a check display with any data entry in a cell
I am creating a simple spreadsheet for teachers and want to have only a check mark displayed regardless of what they type into a cell. Insert the check mark symbol you want from the Insert-Symbol menus int a reference cell for your formula. Then your formula in B2 would be. =IF(A2>0,$H$2,"") A2 is where the data is entered by the teachers, $H$2 is where yo inserted the check mark symbol for your reference. You can then dra this down for each row of data. Cheers, Stev -- Steve ----------------------------------------------------------------------- SteveG's Profile: ...

Total number of Jan 2007 entries in a list of date formatted field
I have a report that captures work done by sales reps. For each entry there exists a date. This report is exported in Excel format and the date is captured as mm/dd/yyyy hh:mm. I would like to have a column that lists the number of work entries by Jan 2007, Feb 2007, Mar 2007, etc. I am at a loss as to how I can conditionally count the occurrence based on the month and the year in this date field. Thanks in advance. =SUMPRODUCT(--(YEAR(B2:B200)=2007),--(MONTH(B2:B200)=1)) where B2:B200 holds the dates you can expand on that if you want to count for an individual =SUMPRODUCT(--(A...

Money 2004 doesn't list available CD-R/CD-RW to back up to....
In Money 2004, why wouldn't it list an available CD-RW to back up to in the drop down box at Tools/Options/Backup? According to this article in the MS Knowledge Base: http://support.microsoft.com/default.aspx?kbid=265130&Product=mny http://tinyurl.com/4bzoj ....it should list it, and on another machine that I have Money 2004 installed on, it lists the A: and a ZIP drive I have installed as D:, but no CD-RW drive. What am I missing that's keeping these two machines from seeing the CD-R/CD-RW as an available drive to write to? -- bill evans WHEvansIIINO@SPAMcharter.net Ha...