Hi
I have a userform that have a code that adds data to a tabel. I have a strange problem.
When I click the button the first time it works great. It adds the new row in the tabel but when I try to add the second product I get this error:
Run-time error '2147417848(80010108)':
Method 'Add' of object 'ListRows' failed
I have checked the line that fails and it is this line in my code: Set newrow = tbl.ListRows.Add
Here is my button code
Hope some one can help me out here, thanks
I have a userform that have a code that adds data to a tabel. I have a strange problem.
When I click the button the first time it works great. It adds the new row in the tabel but when I try to add the second product I get this error:
Run-time error '2147417848(80010108)':
Method 'Add' of object 'ListRows' failed
I have checked the line that fails and it is this line in my code: Set newrow = tbl.ListRows.Add
Here is my button code
Code:
Private Sub cmdAddProduct_Click()
Application.ScreenUpdating = False
If cmdAddProduct.Caption = "New Product" Then
txtUniqID.Value = ""
txtProductname.Value = ""
txtProductnumber.Value = ""
txtProductID.Value = ""
txtVendor.Value = ""
txtCostSafe4.Value = ""
cmdAddProduct.Caption = "Add"
Else
Dim ws As Worksheet
Set ws = Sheets("PARAM")
Dim tbl As ListObject
Set tbl = ws.ListObjects("produkt_liste")
Dim newrow As ListRow
'Henter utregnings tall
Dim Listepris As Variant
Listepris = ws.Range("T7")
Dim Partnerpris As Variant
Partnerpris = ws.Range("T8")
Dim Pris100 As Variant
Pris100 = ws.Range("T9")
Dim Pris500 As Variant
Pris500 = ws.Range("T10")
Dim Pris1000 As Variant
Pris1000 = ws.Range("T11")
Dim Pris5000 As Variant
Pris5000 = ws.Range("T12")
Dim Pris10000 As Variant
Pris10000 = ws.Range("T13")
Dim Pris25000 As Variant
Pris25000 = ws.Range("T14")
Dim Pris50000 As Variant
Pris50000 = ws.Range("T15")
Dim Pris100000 As Variant
Pris100000 = ws.Range("T16")
Set newrow = tbl.ListRows.Add
With newrow
.Range(1) = tbl.ListRows.Count
.Range(2) = txtProductnumber.Value
.Range(3) = txtProductname.Value
.Range(4) = txtProductID.Value
.Range(5) = txtVendor.Value
.Range(6) = txtCostSafe4.Value
.Range(7) = .Range(6) * Listepris
.Range(8) = .Range(6) * Partnerpris
.Range(9) = .Range(6) * Pris100
.Range(10) = .Range(6) * Pris500
.Range(11) = .Range(6) * Pris1000
.Range(12) = .Range(6) * Pris5000
.Range(13) = .Range(6) * Pris10000
.Range(14) = .Range(6) * Pris25000
.Range(15) = .Range(6) * Pris50000
.Range(16) = .Range(6) * Pris10000
'.Range(17) = 5
End With
Dim LastRow As Long
LastRow = Sheets("PARAM").Cells(Rows.Count, 1).End(xlUp).Row
currentrow = LastRow
txtUniqID = Cells(currentrow, 1)
txtProductnumber = Cells(currentrow, 2)
txtProductname = Cells(currentrow, 3)
txtProductID = Cells(currentrow, 4)
txtVendor = Cells(currentrow, 5)
txtCostSafe4 = Cells(currentrow, 6)
ListBoxProdukter.RowSource = "produkt_liste"
cmdAddProduct.Caption = "New Product"
End If
Application.ScreenUpdating = True
End Sub
Hope some one can help me out here, thanks