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????
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?
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
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.