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
3857 Views

Similar Articles

[PageSpeed] 33

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:

Manufacturing Order Entry BOM Revision
Here is the situation, Our BOM's have a revision, for example 603-001 when I change a MO from Open to Released. We update the BOM Revision to 603-002. I enter a component transaction entry pick document, and the then look up the MO on the MO Entry window and the Revision has updated to 603-002 (new revision) however the picklist is still the 603-001 (which is what I want) How come the MO entry window shows the most current BOM revision instead of the revision the MO was released at? -- Doug GP Manufacturing records the revision number but does not really support r...

distribution lists...
I am attempting to send a customer newsletter to 200+ people. The newsletter is aa Word html doc. I sent it from the "Send To" command to a test distribution list of two people and it worked fine. When I send it to the one with 200+ people, I get the following message in Outlook: Your message did not reach some or all of the intended recipients. The following recipient(s) could not be reached: (The name of each person in my distribution list, then) None of your e-mail accounts could send to this recipient I have attempted to send this using other methods, and this is the only ...

"Fax recipient" missing the 'command' box
I am trying to add the "FAx Recipient" to the command box. DO I have to install a macro for this or? In my Word program "Fax Recipient" was in the command box and I was able to drag it to my tool bar. ...

Create Drop Down Box populated by a List
Would someone please tell me if I can Create a Drop Down Box populated by a List from another Worksheet which will Select an item from the Drop Down Box populated by the List from the other Worksheet as Input a given Cell. The Drop Down Box should appear and work that way for any selected Cell. thanks, Ted Hi Ted, You will need to name the list from the other sheet. So, select the list, name it and then in the data valadation allow list and in source box enter =TheNameOfTheList. HTH Regards, Howard "Ted_MD" <TedMD@discussions.microsoft.com> wrote in ...

List views
I have a list view in which I have selected grid lines in report mode. The grid lines show ok until I scroll down and then the horizontal line fall out of step colliding with the text. Does anyone know what is happening here and how to fix it? >I have a list view in which I have selected grid lines in report mode. The >grid lines show ok until I scroll down and then the horizontal line fall out >of step colliding with the text. > >Does anyone know what is happening here and how to fix it? Sadly, the fix is to switch off the grid lines :( PSS ID Number: 813791 "B...

Word 2007: Multi-level lists
Howdy: I'm numbering the appendices using a multi-level list. The first level uses Alphas where the number of appendices goes beyond Z i.e. A B C .... X Y Z AA BB CC ... ZZ Is there any way that I can change the format so that when the list reaches Z, the numbering continues as follows: A B C ... X Y Z AA AB AC ... Thanks, -- Kim See the "Generate a number sequence like Excel uses to number columns" item under the Nifty Numbering section of fellow MVP Cindy Meister's website at: http://homepage.swissonline.ch/cindymeister/ -- ...

How to import address list tables into Excel
I have an address list in Word that looks like this: ____________________________________ | Mr Smith | | 34 swanky st. | | Bufftton 3454-123 | | UK | |___________________________________| | Fat Bread Co. | | Attn. Justin Jock | | 453 Long Drive | | Staten Island | | 232434...

Setting the default contact list for Outlook 2007
When I create an email message, and click on "To" to search my contact list, by default it always goes to the Global Address List. Is there a way to make my Contact List the default? "brenda" <brenda@discussions.microsoft.com> wrote in message news:FED962FD-27E7-42BA-B0CE-FEA9256DDEC4@microsoft.com... > When I create an email message, and click on "To" to search my contact > list, > by default it always goes to the Global Address List. Is there a way to > make my Contact List the default? When that Address Book window opens, click Tool...

Specific cell values
Hi everyone, i need to acheive the following but i'm not sure how to do it. i have a cell (K49), the cell needs to collect specific data from a range ( D7:D32 ) on the same worksheet. it needs to look in the range and if the cell value is CNC, then add the figure form the same row in column E. Example: D E F glass £200 26 August 05 metal £650 26 August 05 wood £300 26 August 05 CNC £1000 ...

How to set up emails with specific domains
Hi all, 1 more question: how do I set up email addresses with specific domains - not the usual @hotmail / @yahoo but company ones made specifically for the company. Regards & thanks Sketch Sketch <sketcher@eircom.net> wrote: > how do I set up email addresses with specific domains - not the usual > @hotmail / @yahoo but company ones made specifically for the company. In Outlook, Tools>E-mail Accounts>Add a new e-mail account. In Outlook Express, Tools>Accounts>Add. -- Brian Tillman You need to consult the documentation for the mail server hosting your =...

GP 10.0 Purchase Order Generator is not listed why?
Hi, When I tried to open Transactions >> Purchasing preview window, Purchase Order Generator was not listed. Note: I do have Purchase Order Proccessing Module. One more thing, Every time I click home button (GP 10.0 home page), I got an error has occurred in the script on this page. How can fix it? Thanks in advance ...

hide names in distribution list
How can I hide names in distribution list? Using outlook 2002? Not possible with an Outlook/MAPI DL....I'd suggest putting your own name in the TO field, and put the DL/recipient names in the BCC (blind carbon copy) field. robert wessel wrote: > How can I hide names in distribution list? > Using outlook 2002? Use the BCC field. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the Swen virus, all e-mails sent to my actual account will be deleted w/out reading. After searching google.groups.com and finding no answer robert we...

Meeting Organizer for Public Folder Calendar Entries
I need to setup a master calendar in public folders for my company to use. One of the problems we're trying to resolve is that when someone adds an entry to the calendar, and that entry is viewed by someone else, the person viewing it shows up as the meeting organizer under the scheduling tab instead of the person who created the entry. What do we need to do to make this information show up accurately? It would be much more useful if we could actually see who created the appointment. Thanks, Carl ...

Migrating Distribution Lists from 5.5 to 2K3 InterOrg
Hey everyone, Thanks in advance for any help. Here's my issue: Distribution Lists are one major limitation with Microsoft's Inter-Org Sync Tool. Basically, the Distribution Lists are brought over as a contact, and don't contain any members. In researching possible solutions (other than expensive 3rd party software) I found KB328871 that states I can "convert the distribution list to a public folder" and then migrate the public folder. . . . . hm. Anyone have any experience with this, or know what this means? Thanks! Try the script at http://www.msd2d.com/fileU...

eVC how to display color dialog box
hi, Am having trouble displaying the color dialog box. CColorDialog is not supported on WCE. Any help welcome. tnx in advance, DNA ...

Combo Box Resizes when clicked ... why? #2
In Excel 2000, activeX controls such as command buttons, combo boxes, check boxes and option buttons will display inaccurately until they receive focus. Fonts and symbols used in the control often appear distorted until clicked. For example, with the combobox, the dropdown arrow appears scrunched. With command buttons it looks like the height and width are both increased by 1 when clicked and then the button returns to the wrong size when another control receives the focus. This occurs on multiple machines running Office XP, with and without service packs 1 and 2 installed. The problem does no...

How to change saving directory for my contact list?
Does anyone have any suggestions on how to change saving directory for my contact list? I am using XP with SP3 and Outlook Express, my system is installed on C drive, whenever I retore my system on C drive, my contact list is gone, is there any approach to relocate my contact list into D drive, so I still can keep my contact list after my system is restored. Does anyone have any suggestions? Thanks in advance for any suggestions Eric > ...is there any approach to relocate my contact list into D drive Only if you move your entire message store to the D drive (which better not...

How can I show a dialog box "Run As Other User" under Windows2000?
How can I show a dialog box "Run As Other User" under Windows2000? do this programmatically "Marco" <sorry@nomail.com> д���ʼ� news:eVZfAcFqDHA.688@TK2MSFTNGP10.phx.gbl... > How can I show a dialog box "Run As Other User" under Windows2000? > > ...

PC Dead, XP HD to new box
My XP PC died. I bought a new PC, Exchanged HD's, but XP will not complete boot up, It gets to recognizing there is new hardware and asks: "New hardware found, do you want to Install??" And " Do you want broadband or Dial-up?" The Old XP PC had PS/2 Keyboard & PS/2 mouse. New has USB Keyboard & mouse. I would suspect that is at least the 'new hardware' found. I can't answer the question as the new PC does not pass the input from USB input to the old XP system. IS THERE, a way to use the new PC's Windows 7 64bit home ...

Query based distribution list problem
Running exchange 2003. Our query based lists work fine except the sender gets an error message for accounts that have expired. Is there a way to get around this? TIA...Bob Did you mean accounts that are disabled? Accounts with expired passwords shouldn't have an issue receiving mail, afaik. -- Bharat Suneja MCSE, MCT www.zenprise.com blog: www.suneja.com/blog ----------------------------------------- "Fuzzy Logic" <bob@arc.ab.caREMOVETHIS> wrote in message news:Xns974A7C1C06982bobarcabca@207.46.248.16... > Running exchange 2003. Our query based lists work fine ...

Text Box In Report
I used this expression in my text box in report =(Abs(Sum(([mthtag]="Current Month" And [ACCTSTAT]="Current")*[NET_BAL]))) How to use sort of the same expression of the above but to display text data only. I tried to use this expression but failed =([mthtag]="Current Month" And [ACCTSTAT]="Current")*[Branch] Thanks =IIf([mthtag]="Current Month" And [ACCTSTAT]="Current",[Branch],"") "zyus" wrote: > I used this expression in my text box in report > > =(Abs(Sum(([mthtag]="Current...

Message box ?
How do you get multiply lines of text with in a message box? formatting as line 1 "text " line 2 "text " etc -- Db1712 ------------------------------------------------------------------------ Db1712's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=15912 View this thread: http://www.excelforum.com/showthread.php?threadid=320495 Try something like MsgBox "Line 1" & vbNewLine & _ "Line 2" -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Db171...

Global Address list #8
Migrated from Exchange 2000 to 2003. All servers are exchange 2003 except one. When I shutdown the exchange 2000 server, users cannot access the Global address list. I need to retire the last e2k server. Have you migrated all the mailboxes etc. from the 2000 machine? Would you need to migrate your global addy book from the 2000 machine? If it's still a production machine and it hasn't been shifted to your 2003 machines then that may be it. But I am sure you've already done this. It may be that there have been changes made to your 2000 machine and those changes may no...

print to pdf without prompt or dialog box
I want a command button to print a report to pdf without user's interaction (no prompt, no dialog box or overwritten prompt). My report name is: rptName My printer driver is: CutePDF Writer I want file in: S:\apps\phonebook\ The file name is: phone.pdf Can anyone help me with the vba code? Thanks. The cute pdf writer does not supprot automaton, and thus you can't supply the outpu file name. Fruhter, you have to isntall cutepdf as a priner, and ufthter more you then have to swith ms-access to that printer. You better off to dump the cutePDf and use stehpans soltiostn here: ht...

Picture in comment box
Can someone remind me how to insert a picture in a cell comment box. Thanks Peter Hi, Have a read of Debra's explanation. http://www.contextures.com/xlcomments02.html#Picture Cheers Andy Peter Andrews wrote: > Can someone remind me how to insert a picture in a cell comment box. > > Thanks Peter > > -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info "Peter Andrews" <p.andrews@blueblueyonder.co.uk> wrote in message news:ec7Gf.271945$vl2.119016@fe2.news.blueyonder.co.uk... > Can someone remind me how to insert a picture in a cell c...