Solved

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

Posted on 2013-12-20
21
6,612 Views
Last Modified: 2016-09-26
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?
0
Comment
Question by:jhseymour113
  • 7
  • 5
  • 4
  • +4
21 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 39732882
Upload what you have done in a simple database. Then explain what the output is.
0
 
LVL 75
ID: 39732946
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
 

Author Comment

by:jhseymour113
ID: 39733762
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
 

Author Comment

by:jhseymour113
ID: 39733767
By the way, I appreciate the suggestion for the third party solution, but this is not the route I want to take.
0
 
LVL 84
ID: 39735748
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
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39736286
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
 

Author Comment

by:jhseymour113
ID: 39736340
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
 

Author Comment

by:jhseymour113
ID: 39736343
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
 
LVL 75
ID: 39736542
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
 

Author Comment

by:jhseymour113
ID: 39742582
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 24

Accepted Solution

by:
Bitsqueezer earned 500 total points
ID: 39744762
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
 

Author Comment

by:jhseymour113
ID: 39744953
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
 

Author Closing Comment

by:jhseymour113
ID: 39744954
see my posted response
0
 
LVL 24

Expert Comment

by:Bitsqueezer
ID: 39745096
You're welcome, I'm glad if I could help you with this.
0
 

Expert Comment

by:Martin Heinrich
ID: 41814887
Hi!
I cannot download the zip file!
0
 
LVL 24

Expert Comment

by:Bitsqueezer
ID: 41814946
Hi,

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

Cheers,

Christian
0
 

Expert Comment

by:Martin Heinrich
ID: 41814950
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
 
LVL 24

Expert Comment

by:Bitsqueezer
ID: 41815054
Hi Martin,

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

Cheers,

Christian
0
 

Expert Comment

by:Martin Heinrich
ID: 41815480
Hi!

Danke Christian, jetzt ist es gegangen!

Ist ja eine tolle Sammlung die du da hast!

LG
Martin
0
 
LVL 24

Expert Comment

by:Bitsqueezer
ID: 41815841
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
 

Expert Comment

by:Martin Heinrich
ID: 41816124
Hab ich schon gesehen!
THX dafür!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now