Andy Lacey
andy at minstersystems.co.uk
Wed Jun 6 11:31:13 CDT 2012
I asked a question recently about searching a multi-select list control to position yourself at a point in the list. Here's the code I used in the end. It uses the list control's own .recordset which I didn't know it had until now. It's a little flakey in that if you run it immediately on opening the form sometimes it finds the record and sometimes not, but it always works if the list control has been selected by the user first and then this is run (rather than run immediately on load of form for example). Really odd. If anyone can come up with a 100% solution that'd be great. For CurrentRow = 0 To Me!lstOptions.ListCount - 1 If Left(Me!lstOptions.Column(1, CurrentRow), intL) = strSearch Then Me!lstOptions.Selected(CurrentRow) = True With Me!lstOptions.Recordset .FindFirst "KeyField = '" & Me!lstOptions.Column(0,CurrentRow) & "'" End With Exit For End If Next CurrentRow This presumes: - strSearch is search string - column(0) of list is unique id - column(1) of list is descriptor you're searching on - replace KeyField with field name of your unique id Hope it's useful to someone. Regards Andy -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: 29 May 2012 16:18 To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] Multi-select listbox - Solved ...And the answer is.......? ;-) Jim -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Andrew Lacey Sent: Tuesday, May 29, 2012 8:05 AM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Multi-select listbox - Solved It's ok I've solved it myself Andy On 29 May 2012 at 14:46 Andrew Lacey <andy at minstersystems.co.uk> wrote: > Hey all, here's a rarity, an actual Access question. > > > > Given a multi-select listbox what I want to achieve is this: > > - user types a search value in a textbox > > - routine searches for the first occurrence of search value in the list > > - that first occurrence is selected > > > > I have all of that working BUT if the first occurrence is above or below > what's visible on-screen the entry is selected but can't be seen without > scrolling. What I want to do is reposition the list so the user can see the > entry that has been found and selected. I reckon if it wasn't multi-select > then setting the listbox's Value property would probably work but that's no > use on a multi-select. Anyone know how to achieve this? > > > > Cheers > > > > Andy > > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com