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

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiple Listboxes, concatenate into Single Textbox

I've seen many answers on how a multi select listbox can be concatenated into a textbox.

But what I'm after is to be able to select a single element of 4 different list boxes to concatenate into a single textbox.

Can anyone explain how this is done, or if it is even possible, it may just be a simple tweak to the method I described above.

Thank you.
Nov 9 '11 #1
9 4791
ADezii
8,834 Expert 8TB
Are the 4 List Boxes in question Multi-Select? If they are Multi-Select, what single Element from the Selections do you want to extract and concatenate into a Text Box?
Nov 9 '11 #2
They're single-select, so one list box might be the company name, the other the product name etc.

Essentially building a product name (in the textbox) based on values chosen from each list box.
Nov 9 '11 #3
ADezii
8,834 Expert 8TB
This can definitely be done, give me a little time to come up with the correct approach.
Nov 9 '11 #4
ADezii
8,834 Expert 8TB
  1. I'm not sure as to whether or not the 4 List Boxes on your Form are the only ones, so we need a method to differentiate these 4.
    • Set the Tag Property of these 4 Text Boxes to the String 'Incl'.
  2. Name these 4 List Boxes as:
    • lst1, lst2, lst3, lst4
  3. Name the Text Box that will display the results of concatenating all 4 List Box Values
    • txtResults
  4. I'll display the Code, but download the Attachment in order to obtain a clear Picture of exactly what is going on.
    Expand|Select|Wrap|Line Numbers
    1. Dim ctl As Control
    2. Dim strBuild As String
    3.  
    4. For Each ctl In Me.Controls
    5.   With ctl
    6.     'Grab all List Boxes with Tag Property = 'Incl'
    7.     If .ControlType = acListBox And .Tag = "Incl" Then
    8.       If Not IsNull(.Value) Then
    9.         strBuild = strBuild & .Value & ","
    10.       End If
    11.     End If
    12.   End With
    13. Next
    14.  
    15. If Len(strBuild) = 0 Then
    16.   Me![txtResults] = "No Items Have Been Selected"
    17.     Exit Sub
    18. End If
    19.  
    20. 'Remove Trailing ',', if present
    21. If Mid$(strBuild, Len(strBuild)) = "," Then
    22.   strBuild = Left$(strBuild, Len(strBuild) - 1)
    23. End If
    24.  
    25. Me!txtResults = strBuild
  5. Any questions, feel free to ask.
Attached Files
File Type: zip Multiple Listboxes.zip (20.8 KB, 210 views)
Nov 9 '11 #5
Mihail
759 512MB
Hello !
I don't try ADezii's solution but I think it is a little bug here:
The name of product must be built in a certain sequence.
For Each ... Next structure is unpredictable as sequence (or it is ? )

Assuming that your list boxes are bound a solution can be:
Expand|Select|Wrap|Line Numbers
  1. YourTxtBox.Text = lst1.Column(n1) & " - " & lst2.Column(n2) & " - " & lst3.Column(n3) & " - " & lst4.Column(n4)
Nov 10 '11 #6
ADezii
8,834 Expert 8TB
  1. The Control Sequence is determined by the Time of Creation.
  2. The assumption here is that the 4 List Boxes are distinct, with each List Box representing a different entity. This may/may not be true.
  3. Good points, Mihail.
Nov 10 '11 #7
Thanks very much for the replies!

I have one error with the code you provided (ADezii) with the line:

If Mid$(strBuild, Len(strBuild)) = "," Then

Apparently there is a missing reference, is there a minor tweak I could make to the code to fix this?

Thanks again.
Nov 10 '11 #8
ADezii
8,834 Expert 8TB
@Gwyn:
You should not be getting an Error on this Line, but try an alternative:
Expand|Select|Wrap|Line Numbers
  1. If Right$(strBuild, 1) = "," Then
Nov 10 '11 #9
NeoPa
32,556 Expert Mod 16PB
Assuming a form with a TextBox control called txtResult, four ListBox controls called lstA, lstB, lstC & lstD and a requirement to separate each string with a string such as " - " then the formula would simply be :
VBA:
Expand|Select|Wrap|Line Numbers
  1. Me.txtResult = Me.lstA & " - " & Me.lstB & " - " & Me.lstC & " - " & Me.lstD
Form Design:
Expand|Select|Wrap|Line Numbers
  1. =[lstA] & " - " & [lstB] & " - " & [lstC] & " - " & [lstD]
There is also an assumption that all ListBoxes reflect values. If the reverse is true and you need only those separators that appear between valid values then (you should certainly have included that as part of your question and) you would need one value to be guaranteed and would need to use the + concatenator character as well as the & to handle Null Propagation (See Using "&" and "+" in WHERE Clause).
Nov 12 '11 #10

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

Similar topics

9
by: amitavabardhan | last post by:
How Can I extract multiple tiff images into single images through asp programming? Is there any free dll's that I can use in ASP to split multiple tiffs into single tiffs? Any suggestion...
6
by: Ralph2 | last post by:
Some time ago with a lot of help from this group I made a reasonably successful database to keep track of our shop drawings. However the searching mechanism is too complicated for the occasional...
7
by: spamsickle | last post by:
My database stores City and State in two separate columns, but I want to display them on my form as a single field. Since I'm a complete VB novice, I'm not sure how to do this. I bind the data,...
8
by: JReneau35 | last post by:
I am a novice to MS Access. I have about 10 to 15 tables that link to a single form. I use unique ID's to link all of these tables together. Since the ID for the customer never changes, I was...
3
by: Grizlyk | last post by:
Hi, people. Can anybody explain me "multiple 'new' at single line" behavior. Consider: p::p(void*); p::p(void*,void*); new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));
4
by: cyberdrugs | last post by:
Hi guys 'n gals, I have a string which contains multiple spaces, and I would like to convert the multiple spaces into single spaces. Example Input: the quick brown fox jumps ...
5
by: polturgiest | last post by:
hie all i got a form <form name="TEST" method=POST action="test.php"> <input type="text" name="MyInput"> <input type="submit" name="ACTION" value="SAVE">
2
by: aishah | last post by:
hi can anyody help me in giving and example of multiple queries and single query.
2
by: nawedita | last post by:
Hello everyone.. I am trying to use multiple buttons in single php form with validations with given below functions: But i am facing problem when i click on submit button after checking all...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.