Link to home
Start Free TrialLog in
Avatar of John Seymour
John SeymourFlag for United States of America

asked on

How to implement drag-and-drop listboxes in an ms access (2010) form

I have looked at several discussions of how to implement drag-and-drop between listboxes in an Access form, but none has provided enough information for me to get this to work. I actually did make it work from a list box to a text box, but after the program did everything it was supposed to, I got a runtime error saying my application asked the runtime to terminate in an unusual way and then Access crashed.

I have been working at this for some time with and without class modules, but I'm really stuck. Can any one help?
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Upload what you have done in a simple database. Then explain what the output is.
I believe you will find Peter's tool will do this for you:

http://www.peterssoftware.com/dd.htm

With Drag-N-Dropper you can:

Drag text between text, combo, and list boxes, and continuous forms
Drag records between list boxes and between continuous form subforms
Drag text or records from one form to another
Re-order list box items with drag and drop
Execute an SQL statement, or a custom function on drop to handle special processing.
Avatar of John Seymour

ASKER

This is a fairly complicated application, but the drag-and-drop logic follows the example described in

http://social.msdn.microsoft.com/Forums/en-US/1d0a1a6b-11cf-418e-8922-82094d604b4d/newbie-in-vba-drag-and-drop?forum=isvvba


All the controls in the code are MSFORMS2.0 controls.

However I had to substitute a text box for the target (drop) because I can't find any way to get list boxes on a form in design mode that have the WithEvents property. Without this, the list boxes do not have the BeforeDragOver and BeforeDropOrPaste events available which are essential to the process. Finding out how to do this is my primary aim.

Right now, when the data is dropped on the textbox, I update a corresponding listbox. As I said, everything works fine through all the routines in the process, which also update tables, but after the final End Statement, I get the "runtime has been asked to terminate in ..." message and then Access crashes. Figuring this out is secondary to finding out how to get the list boxes to include the BeforeDragOver and BeforeDropOrPaste events (unless that also crashes Access).
By the way, I appreciate the suggestion for the third party solution, but this is not the route I want to take.
All the controls in the code are MSFORMS2.0 controls.
Be careful working with ActiveX controls and Access, even if those controls come from MSFT. In the not-too-distant-future you'll very likely find those controls to be incompatible with the platform, and you'll have to start back at square one. The 3rd party solution that mx suggested works very well.

But it's your app, and you're the one who will have to rework it when they upgrade ...
Is there a reason you want to drag and drop between lists, rather than using a command button to do the migration?

I generally just use two side-by-side lists, allow multi-select in each and put two command buttons (pointing left or right) between them in order to migrate the selected item(s) from one list to the other.

Obviously this involves code to update the appropriate tables and refresh the lists, but it is very simple to implement.
I'm moving people between 24 different lists and also from a treeview control. Otherwise I agree, the side-by-side approach would work.
I'll be happy to re-write this code when and if Microsoft ever chooses to provide a new set forms controls. The inconsistencies in Forms 2.0 are horrendous. Unfortunately I haven't seen any standard alternatives right now.
I should also note that ...  Peter's solution is a VBA - no DLLs or ActiveX controls. And it's virtually free.  I've used it several times and it really is nothing sort of amazing, as are his other products.  
You might a least download the demo - wherein you can check out the full functionality - including dragging between List boxes.

mx
I'd just like an answer to how I get listboxes on an Access form that have  BeforeDragOver and BeforeDropOrPaste events. That's the basis of the original question.
ASKER CERTIFIED SOLUTION
Avatar of Bitsqueezer
Bitsqueezer
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Christian - Thank you for this wonderful response. Figuring out the code was a major learning experience, a real bonus beyond the fact that it will solve my problem. I have a lot of work to incorporate this so I haven't tested it in my app yet, but it looks like a perfect answer for me. Thanks again.
see my posted response
You're welcome, I'm glad if I could help you with this.
Avatar of Martin Heinrich
Martin Heinrich

Hi!
I cannot download the zip file!
Hi,

you can also download it from my download page:
Bitsqueezer's Access Downloads

Cheers,

Christian
Hi Christian!

I'm sorry but it won't work!
The link opens in a new tab with the adress https://www.experts-exchange.com/questions/28323400/How-to-implement-drag-and-drop-listboxes-in-an-ms-access-2010-form.html?anchorAnswerId=41814946#a41814946

Can you help?

Regards
Martin
Hi Martin,

try it with copy and paste the link (remove the spaces):
www. ccedv. de/ downloads / en

Cheers,

Christian
Hi!

Danke Christian, jetzt ist es gegangen!

Ist ja eine tolle Sammlung die du da hast!

LG
Martin
Hallo Martin,

freut mich, wenn's geklappt hat. Für deutsche Besucher sind dort auch noch einige Downloads, die hier noch nicht veröffentlicht sind, da die Kommentare noch auf Deutsch sind.

Gruß

Christian
Hab ich schon gesehen!
THX dafür!
Hi,

I've created a new version of the drag&drop class module. This one has an easier method to add as many controls as you want (only listboxes/textboxes). It also has a new parameter to be able to automatically use drag&drop between the desired controls in both directions. Additionally it can drag&drop between textboxes, listboxes and between textboxes and listboxes.

If i.e. a comma separated list is entered and dragged to a listbox it can be added as separated entries into the listbox. If a list of entries is moved to the textbox it displays a comma separated list of the dragged entries.

Another new feature is that dragging is no longer possible if the user tries to start dragging from an empty listbox/textbox or in a filled listbox from a row with no contents.

Maybe useful for someone who reads this thread.

CCDragDropV2.zip

Cheers,

Christian