Listbox (multi-select) - Click and Key events (1 Viewer)

dazza61

Registered User.
Local time
Today, 14:29
Joined
Feb 7, 2006
Messages
60
Hi guys,

I have a multi-select listbox of employees on Form A that when single-clicked or drag-selected (to select a group) - fires a loop through items sub to create a recordource for a second "detail" form B

I also get the above code to fire when I use the Up and Down arrow keys on my keyboard. What I end up with is a listbox that you can 1) Click single entries on 2) Drag across a multiple selection or 3) Use the up/down arrows on my keyboard with the end result that these actions update/requery the second Form (Form B) providing either a single record or multiple records...

The code has worked well over the last 2 years or so until I recently added code to display images of our employees...this code fires in the Current event of Form B...

What I now get is

1) Single On-Click events work fine - bringing a single candidates' details up with the correct image
2) Drag select works okay - select 10 items and 10 items are ready to scroll through on Form B - if the first record dragged over has an image - this image displays properly....

3) The problem is the up/down keys on my keyboard - what often happens is the wrong record is shown in Form B or the wrong image is shown or a combination of both...especially when you go from up to down and vice versa...

Anyone know why Key events work differently to Click events in listboxes?

Any ideas or help would be very much appreciated

Darren
 

dazza61

Registered User.
Local time
Today, 14:29
Joined
Feb 7, 2006
Messages
60
Sorry this question got listed twice - I was at work and our internet was really slow and I couldn't seem to post a message but somehow both must have got through - I've deleted the duplicate question now...
 

dazza61

Registered User.
Local time
Today, 14:29
Joined
Feb 7, 2006
Messages
60
Ok I managed to work out through trial and error how to solve my problem - and for the benefits of others, I'll explain how ...

Firstly, because the multi-select listbox was set to extended - the well known and accepted way to retrieve a multiple selection is to loop through the items to create data for a recordsource, etc...

Stupid me was using this same technique for when only ONE item in the listbox is selected....what I was getting was when I clicked the listbox I got the correct record displayed in my second detail form, but when I used the up/down keys on my keyboard I was always one record behind (or in front depending on whether your going up or down the listbox....)

I was trying all kinds of different events to catch things, setting boolean triggers for this and that.....until it dawned on me....

Simply use A for single selections and B for multiple selections...

A) varFilt = "[EmployeeID] = " & varEmpID 'use this WHERE clause for singular listbox selections.........and

B) varFilt = "[EmployeeID] IN (" & strWhere & ") ' strWhere can contain all the items selected in the listbox - use this WHERE clause for a MULTIPLE selection...

Then all I do is use the Listbox.Count routine to decide whether to run A or B above....

Assign all this to the AfterUpdate event of the listbox and I'm sorted...

Hope this helps someone

Darren
 
Last edited:

Users who are viewing this thread

Top Bottom