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.
9 4791
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?
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.
This can definitely be done, give me a little time to come up with the correct approach.
- 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'.
- Name these 4 List Boxes as:
- Name the Text Box that will display the results of concatenating all 4 List Box Values
- I'll display the Code, but download the Attachment in order to obtain a clear Picture of exactly what is going on.
-
Dim ctl As Control
-
Dim strBuild As String
-
-
For Each ctl In Me.Controls
-
With ctl
-
'Grab all List Boxes with Tag Property = 'Incl'
-
If .ControlType = acListBox And .Tag = "Incl" Then
-
If Not IsNull(.Value) Then
-
strBuild = strBuild & .Value & ","
-
End If
-
End If
-
End With
-
Next
-
-
If Len(strBuild) = 0 Then
-
Me![txtResults] = "No Items Have Been Selected"
-
Exit Sub
-
End If
-
-
'Remove Trailing ',', if present
-
If Mid$(strBuild, Len(strBuild)) = "," Then
-
strBuild = Left$(strBuild, Len(strBuild) - 1)
-
End If
-
-
Me!txtResults = strBuild
- Any questions, feel free to ask.
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: - YourTxtBox.Text = lst1.Column(n1) & " - " & lst2.Column(n2) & " - " & lst3.Column(n3) & " - " & lst4.Column(n4)
- The Control Sequence is determined by the Time of Creation.
- 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.
- Good points, Mihail.
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.
@Gwyn:
You should not be getting an Error on this Line, but try an alternative: - If Right$(strBuild, 1) = "," Then
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: - Me.txtResult = Me.lstA & " - " & Me.lstB & " - " & Me.lstC & " - " & Me.lstD
Form Design: - =[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).
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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,...
|
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...
|
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));
|
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 ...
|
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">
|
by: aishah |
last post by:
hi
can anyody help me in giving and example of multiple queries and single query.
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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: 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...
| | |