Listbox .additem / .removeitem ?

  • Thread starter kelly draper via AccessMonster.com
  • Start date
K

kelly draper via AccessMonster.com

I'm running access 2000 and my listbox's dont support the .addItem /
..removeItem method.
is that normal for 2000? is there a reference i have to turn on? or is mine
just broken.

Thanks.
 
R

Rick Brandt

kelly said:
I'm running access 2000 and my listbox's dont support the .addItem /
.removeItem method.
is that normal for 2000? is there a reference i have to turn on? or
is mine just broken.

Thanks.

I believe that was added in a later version.
 
G

George Nicholson

FWIW Confirmation: the AddItem and RemoveItem methods for Access List &
Combo Boxes are listed as "New Methods" in 2002/XP Help.
 
M

MikeB

To AddItem in AC2000:

Private Sub ListAddItem(LB As ListBox, strItemToAdd As String)
If LB.RowSource = "" Then
LB.RowSource = IIf(LB.RowSource = "", strItemToAdd, "")
Else
LB.RowSource = LB.RowSource & ";" & strItemToAdd
End If
End Sub


To RemoveItem in AC2000:

Private Sub RemoveSelected(LB As ListBox)
Dim i As Integer
Dim s As String
If LB.ListCount = 0 Then
Exit Sub
End If
With LB
For i = 0 To .ListCount - 1
If .Selected(i) <> True Then
s = s & .ItemData(i) & ";"
End If
Next
s = Mid$(s, 1, Len(s) - 1)
LB.RowSource = ""
LB.RowSource = s
End With
End Sub
 
K

kelly draper via AccessMonster.com

Thanks guys. thats what I was afraid of. c'est la vie.
Just in case any future readers of this post might want to know how to do
it by code and dont want to use the table and requery method (which i've
used before but wasnt entirely feasible for this situation i have now) i've
pasted the code I used to simulate the .remove technique. (adding an item
is fairly simple so i didnt bother including it here.) this example doesnt
add to a new list as it deletes from the old one cuz thats not what i
wanted it to do but if somebody else does, its easy enough to modify:
P.S. this example is for a 2 column list.
(add this to an event. like a buttons OnClick or something)

a = ListToDeleteFrom.RowSource
b = ListToDeleteFrom.ListCount
e = ListToDeleteFrom.ListIndex
If e = -1 Then MsgBox ("No Name Selected"): Exit Sub

d = ""
For c = 0 To b

If c <> e Then
f = ListToDeleteFrom.Column(0, c) & ";" & ListToDeleteFrom.Column(1, c)
& ";"
If f <> ";;" Then d = d & f

End If
Next c

If Len(d) > 1 Then d = left(d, Len(d) - 1) Else d = ""

ListToDeleteFrom.RowSource = d
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top