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?
jhseymour113Asked:
Who is Participating?
 
BitsqueezerConnect With a Mentor Commented:
Hi,

maybe the attached demo database can help you with this issue. As you see, there is not much code needed to make that possible. You can of course also add further events to the class module as you want.

I've based the class module to be able to use Listboxes as source controls and Listboxes and/or Textboxes as target. The demo form shows the result.

The class module only provides the basic functionality but will not change the values of the target control. For this purpose the events are delivering the selected values to the form and the form is responsible to do whatever it wants with the values. In the demo I only filled the textboxes with the values.
On this way the class module is very universal and you can see the simple code which makes it possible to extend the class module to use other control types also.

Cheers,

Christian
CCDragDrop.zip
1
 
hnasrCommented:
Upload what you have done in a simple database. Then explain what the output is.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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.
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
jhseymour113Author Commented:
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).
0
 
jhseymour113Author Commented:
By the way, I appreciate the suggestion for the third party solution, but this is not the route I want to take.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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 ...
0
 
Dale FyeCommented:
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.
0
 
jhseymour113Author Commented:
I'm moving people between 24 different lists and also from a treeview control. Otherwise I agree, the side-by-side approach would work.
0
 
jhseymour113Author Commented:
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.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
0
 
jhseymour113Author Commented:
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.
0
 
jhseymour113Author Commented:
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.
0
 
jhseymour113Author Commented:
see my posted response
0
 
BitsqueezerCommented:
You're welcome, I'm glad if I could help you with this.
0
 
Martin HeinrichCommented:
Hi!
I cannot download the zip file!
0
 
BitsqueezerCommented:
Hi,

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

Cheers,

Christian
0
 
Martin HeinrichCommented:
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#a41814946

Can you help?

Regards
Martin
0
 
BitsqueezerCommented:
Hi Martin,

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

Cheers,

Christian
0
 
Martin HeinrichCommented:
Hi!

Danke Christian, jetzt ist es gegangen!

Ist ja eine tolle Sammlung die du da hast!

LG
Martin
0
 
BitsqueezerCommented:
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
0
 
Martin HeinrichCommented:
Hab ich schon gesehen!
THX dafür!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.