Thread: add to listbox
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
ranswrt ranswrt is offline
external usenet poster
 
Posts: 191
Default add to listbox

I cleared the rowsource property for the listbox and I still get the
'permission denied error.

Here is the whole procedu

Private Sub CommandButton11_Click()
Dim aitem(6) As Variant
Dim item As String
Dim num As Integer
Dim xcell As Range
Dim ycell As Range
Dim rng As Range
Dim i As Integer
Dim cntr As Integer

item = Range("currentdb")
item = LCase(item)
aitem(0) = TextBox1.Value
aitem(1) = ComboBox1.Value
aitem(2) = 0
aitem(3) = 0
aitem(4) = 0
aitem(6) = 0
num = Range(item & "itemnum")
cntr = 0
Set xcell = Range(item & "Itemno")
For i = 1 To num
Set ycell = xcell.Offset(i, 1)
If ycell.Value = aitem(0) Then
cntr = cntr + 1
End If
Next
If cntr = 0 Then
If aitem(0) = "" Then
MsgBox ("Enter New Database Item.")
updateDB.TextBox1.SetFocus
Else
If aitem(1) = "" Then
MsgBox ("Select Unit for New Database Item.")
updateDB.ComboBox1.SetFocus
Else
With ListBox1
.AddItem
For i = 0 To 6
.List(num, i) = aitem(i)
Next
End With

Label8.caption = num + 1
End If
End If
Else
MsgBox ("Item '" & aitem(0) & "' already exists, select another item.")
updateDB.TextBox1.SetFocus
End If



End Sub

"Bob Phillips" wrote:

Have you got the ListFillRange/RowSource property set in the design mode? If
so, clear it.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"ranswrt" wrote in message
...
I tried that and I got a 'permission denied' error.

" wrote:

hi ranswrt,
you need AddItem to create a new row in the listbox. try

With ListBox1
.AddItem
For i = 0 To 6
.List(num, i) = aitem(num, i)
Next
End With

stefan

On 25 Apr., 13:46, ranswrt wrote:
I have a form with a listbox with 7 columns and I want add items to the
listbox using textboxes and a commandbutton. when I click the
commandbutton
to add the items in the textboxes to the end of the items in the
listbox I
get an error. the code that I have tried is :

For i = 0 To 6
With ListBox1
.List(num, i) = aitem(num, i)
End With
Next

I get a 'type mismatch error.
What is the best way to enter new items to the end of an existing list
of
items in a listbox that has 7 columns?
Thanks