adding multiple values to a text box

Kempes

Registered User.
Local time
Today, 14:52
Joined
Oct 7, 2004
Messages
327
Hi,

What I am trying to do is selecting single values from a combo box, then when you click an "Add" button, it writes that value to a Single Text field within a form. However, I need it to add other values after the first and not overwrite it within the Text Box.

For example.

If my combo box has values A, B, C

When selecting A then Add, Then selecting B then Add, Then Selecting C then Add, the Text Box Reads

ABC

Hope I have explained in enough detail.
 
Why would you want to do such a thing with a textbox?
 
I've done it several times fro a variety of reasons.
Basically you use this code

textbox1 = textbox1 & " " & combobox1

rather than

textbox1 = combobox1

hope that helps :)
 
workmad3 said:
textbox1 = textbox1 & " " & combobox1

For the sake of being explicit.

Code:
Me.Textbox1 = Me.Textbox1 & ";" & Me.Combobox1



You wouldn't, however, be storing this result in a table, would you? If so, it's a possibility you need a new table.
 
The idea was a quick way of putting several email addresses together in one field.
I know there are other ways of doing this but wanted a quick solution. I needed to retain the addresses chosen in a table.
I have ditched this idea now and found a solution to my problem.

Thanks for the replies though,
 
For the sake of being explicit.

Code:
Me.Textbox1 = Me.Textbox1 & ";" & Me.Combobox1



You wouldn't, however, be storing this result in a table, would you? If so, it's a possibility you need a new table.
Along the same lines, I tried creating a carriage return between the 2 entries:
Me.txt1 = Me.txt1 & vbCrLf & Me.cmb1
This does the job but also creates a carriage return at the start of the textbox.
Anyway to get around this?
Thanks
 
I know there are other ways of doing this but wanted a quick solution
The quickest solution is almost always the sound solution.

Mushing different values together in a single field doesn't save anything, It requires code and violates first normal form. Do it right the first time is my motto. In this case, doing it right doesn't require code at all. Just a separate table and a subform.
 
Wow, almost a 15 year old thread. That must be a record.
 
Along the same lines, I tried creating a carriage return between the 2 entries:
Me.txt1 = Me.txt1 & vbCrLf & Me.cmb1
This does the job but also creates a carriage return at the start of the textbox.
Anyway to get around this?
Thanks
Check the length before using vbcrlf
 
Check the length before using vbcrlf
Please can you explain a bit more?
I want to emulate an enter key press between the different entries that are added to the text box.
But this code also creates an enter key stroke before the first entry of the text box which I dont want.

Code:
Me.txt1 = Me.txt1 & vbCrLf & Me.cmb1
 
Code:
if Len(Me.txt1) <> 0 then
Me.txt1 = Me.txt1 & vbCrLf & Me.cmb1
else
Me.txt1 =   Me.cmb1
End if
 
Code:
If Len(Me.txt1) > 0 then
    Me.txt1 = Me.txt1 & vbCrLf & Me.cmb1
Else
    Me.txt1 = Me.txt1 & Me.cmb1 ' or just Me.txt1 = Me.cmb1
End If

Alternatively check if ASC() of the first character is 13, and if so strip it off?
 

Users who are viewing this thread

Back
Top Bottom