Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending to a text box. 1

Status
Not open for further replies.

youdaman

Technical User
Dec 26, 2001
66
US
I have a list box that I can select products and populate a text box with. However, if I enter (i.e.) 3 items now and want add some later, it overwrites the old data. Does any one know how to append the data rather than writing new data????

tks,
t
 
do you mean you are entering (i.e.) three item codes (or ID's or whatever) into one text box as a string? if so then you need to change your database structure and get it normalized. so tell us more about how your structure is: do you just have one table with one text field in it that holds these item codes?

g
 
I have an unbound list box with banana, orange, pear, apple, grapes as the items. When I select one, the selection is written to the a table in the field equipment purchased. If multiple are selected, then it writes all the items to the equipment purchase field separated by a semi-colon. But if I go back to the record later because someone has purchased a new item, the data that use to be there gets overwritten. The code looks like this:

Private Sub cmdButton_Click()

MyTextBox = ""
Dim intCnt, intNum As Variant

For Each intCnt In MyListBox.ItemsSelected

intNum = intNum + 1 'This numerator will determine if there is
If intNum = 1 Then 'more than one item selected.
MyTextBox = MyListBox.ItemData(intCnt)

Else 'If so then it will add a semicolon.
MyTextBox = MyTextBox & "; " & MyListBox.ItemData(intCnt)
End If

Next

End Sub

Any help you have will be greatly appreciated!!!!
 
Hi!

I agree with GingerR, what would work best is to normalize your data. Then problems like these would not crop up. That said try the following:

Private Sub cmdButton_Click()

Dim intCnt As Variant

If IsNull(MyTextBox) = True Then
MyTextBox = ""
End If

For Each intCnt In MyListBox.ItemsSelected
If MyTextBox = "" Then
MyTextBox = MyListBox.ItemData(intCnt)
Else
MyTextBox = MyTextBox & "; " & MyListBox.ItemData(intCnt)
End If
Next intCnt

End Sub

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top