Code works however receiving Runtime error 380 - Could not set the list property. Invalid property value

Megg

New Member
Joined
Nov 5, 2023
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi there,
I have a userform that contains a listbox that retrieves it's data from a table in a worksheet called Breakdown. The userform has a search function linked to the listbox and has a button to edit and a button to delete. These two buttons open their own userforms - for example the delete button shows a userform asking the user if they are sure they want to delete "________".
The edit button works exactly as intended. However my delete button technically does work, but when clicking yes to confirm deletion a 'Runtime error 380 - Could not set the list property. Invalid property value' pops up.
Even though it does delete the row from the table. Although I can't confirm if it does delete from the listbox as well as the pop up shows as soon as I hit either yes or no to confirm deletion. It does this error even when getting rid of the 'update listbox' part.

Here is my below code related to the delete button.
On the userform called SearchForm (that contains the listbox):
Code:
Option Explicit

Dim tblbreakdownTable As ListObject
Public RecordRow As Long
Dim a As Variant

Private Sub UserForm_Initialize()
  Dim i As Long
  Set tblbreakdownTable = ThisWorkbook.Worksheets("Breakdown").ListObjects("breakdownTable")
 
  With playerList
    a = tblbreakdownTable.DataBodyRange.Value2
    .List = a
    For i = 1 To UBound(a)
      playerList.List(i - 1, 9) = i
    Next

    .ColumnCount = 9
    .ColumnHeads = False
  End With
End Sub

Code:
Private Sub DeleteButton_Click()
  Dim i As Long
  If playerList.ListIndex = -1 Then
    MsgBox "Select item"
    Exit Sub
  End If
 
  ConfirmDelete.DeleteRecord Me, tblbreakdownTable
  a = tblbreakdownTable.DataBodyRange.Value2
  For i = 1 To UBound(a)
    playerList.List(i - 1, 9) = i
  Next
End Sub

ConfirmDelete Userform:
Code:
Option Explicit

Private Sub cmdYes_Click()
    Me.Hide
End Sub

Private Sub cmdNo_Click()
    cmdNo.Tag = vbCancel
    Me.Hide
End Sub

Sub DeleteRecord(ByVal Form As Object, ByVal objTable As Object)
    Dim rngData     As Range
    Dim i           As Long
      
    With Form.playerList
        For i = 1 To 3
            Me.Controls("Label" & i).Caption = .Column(Choose(i, 1, 0, 2))
        Next i
        Form.RecordRow = .List(.ListIndex, 9) 'Retrieves the row number of the sheet
    End With
    Me.Show
    
    If Not Val(Me.cmdNo.Tag) = vbCancel Then
        'Delete record from table
        objTable.DataBodyRange.Rows(Form.RecordRow).Delete
      
        Set rngData = objTable.DataBodyRange
        'update listbox
        With Form.playerList
            .Clear
            .List = rngData.Value2
            .ListIndex = Form.RecordRow - 1
        End With
        
        MsgBox "Record Updated", 64, "Success"
        
    End If
        
        Unload Me
    
End Sub

I'm still fairly new to VBA so any assistance is greatly appreciated! :)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try making this Public "Dim tblbreakdownTable As ListObject". That might be it. Does it occur when the button is pressed?
 
Upvote 0
Unfortunately that didn't work :( . And yes as soon as I press either the Yes or No command buttons on the ConfirmDelete userform it pops up.
When I select debug it highlights - "ConfirmDelete.DeleteRecord Me, tblbreakdownTable" that's under DeleteButton_Click(). But I don't see the issue with it?
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,341
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top