473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,320 developers and data experts.

Double-clicking to move an item between list boxes

patjones
931 Expert 512MB
Sometimes you might have two list boxes side by side, and want to double-click on an item in one box to move it to the other.

For instance, maybe the first list box contains a list of customers, and you want to perform some function (say, email them) that pertains to only a few of those customers. By double-clicking on the customer names you want, you get the desired list in the right hand box.

First, make a generic sub that takes two listbox arguments:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub MoveListItem(lstFrom As ListBox, lstTo As ListBox)
  3.      lstTo.AddItem (lstFrom.Value)
  4.      lstFrom.RemoveItem (lstFrom.Value)
  5. End Sub
  6.  
Then call this sub in the double-click events for the respective list boxes:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub lstA_DblClick(Cancel As Integer)
  3.     MoveListItem Me.lstA, Me.lstB
  4. End Sub 
  5.  
  6. Private Sub lstB_DblClick(Cancel As Integer)
  7.     MoveListItem Me.lstB, Me.lstA
  8. End Sub 
  9.  
Here you'll replace "lstA" and "lstB" with whatever the names of your list boxes are. You could modify this slightly by having a button situated between the boxes, and move the item from one to the other when the button is clicked.

It's a simple task but can come in handy!

Pat
May 1 '08 #1
6 9544
MMcCarthy
14,534 Expert Mod 8TB
Pat

Does this belong in VB. I don't think you can use .AddItem and .RemoveItem in VBA without at least adding a library.

If it needs to be moved just post a comment here and I'll take care of it.

Mary
May 28 '08 #2
patjones
931 Expert 512MB
Pat

Does this belong in VB. I don't think you can use .AddItem and .RemoveItem in VBA without at least adding a library.

If it needs to be moved just post a comment here and I'll take care of it.

Mary
I didn't have any reference issues when using this code in VB 6 (Access). Do you want me to post which references I have enabled just to be sure?

Thanks!

Pat
Jun 10 '08 #3
JustJim
407 Expert 256MB
@zepphead80
Hi Pat,

This is simple and elegant but, sadly errors out for me. Perhaps a library problem as Mary thought. I tried it at home using Access '03/VBA Retail 6.4.8869 with the following references included:

Visual Basic for Applications
Microsoft Access 11.0
Microsoft DAO 3.6
Microsoft ActiveX Data Objects 2.1
OLE Automation

Anything else you have loaded that might be relevant?

The error is 94: Invalid use of Null, and is on .AddItem line of the MoveListItem sub. A little hovering tells me that ListFrom.Value is null as is Me.lstA and Me.lstB from the calling subs.

Also, the helpfile for .AddItem and .RemoveItem states that the list box RowSourceType must be "Value List", which means you would have to build the contents of the first listbox by code or hard key it when you design the form. A pain, but a mild one.

Jim
Apr 15 '09 #4
JustJim
407 Expert 256MB
Sorry, ignore almost all of the above - I had one of the list boxes set to Extended Selection and that messed it up for some reason.

It now works fine with the basic libraries above, thank you.

The comment about the RowSourceType should be noted by others though.

(Blushing)Jim
Apr 15 '09 #5
patjones
931 Expert 512MB
Glad that my post was of assistance to you! No need to blush - show me someone who doesn't make these kinds of mistakes when programming in Access!

Pat
Apr 15 '09 #6
MMcCarthy
14,534 Expert Mod 8TB
Hi Pat

Haven't seen this thread in a while. My misinformation on .AddItem is probably a holdover from some of those earlier versions of Access libraries. I haven't tried to use it in years. I'll have to start experimenting again.

Thanks for the information. I always learn something new from the bytes experts no matter how much I think I know. It's why I love information sharing sites like this. Stops me from getting stuck in old patterns.

Mary
Apr 16 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Sydex | last post by:
When I compile code I get error C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(double)' in this part : double Integration::quad2d(double...
20
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; ...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
10
by: Robert Palma | last post by:
I'm having trouble figuring out how to pass a pointer to a double array (1 dimensional) to a C function. Declaring array as: double xx; Declaring func. int process( double *input ) Calling...
10
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
3
by: BlueTrin | last post by:
I am using a DLL written in C, it uses some pointers on functions, I have defined a wrapper around it in C# which uses some delegates: #region Delegates and Marshalling to call solvopt public...
67
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the...
1
by: JWest46088 | last post by:
I keep getting these error messages: area(double,double) in Rectangle cannot be applied to () return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter(); ...
2
by: dj10fld | last post by:
I am getting a (cannot convert double to double in assignment errors) here is a part of my code #include <iostream> #include <iomanip> #include <cmath> using namespace std; #define MaxSize...
2
by: Genro | last post by:
#include<stdio.h> #include<TX/graphics.h> #include<time.h> // I need help! struct Krug{ double _x; double _y; double _skox; double _skoy; double...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.