Hi All,
Trying to get listview to populate after the user inputs names into a second form. The firstname and second name are put into excel cells.
When Form 1 initializes the listview populates with this code:
On Form 2 when button is clicked, data is added to two cells, and trying to run the listview command again on Form 1 comes up with error: Run-time error '424'. Object required.
Been trying to fix this for a few days but most suggested is to use different Form options e.g. Forms!(formname) etc.. which is not working. Any help appreciated!
Trying to get listview to populate after the user inputs names into a second form. The firstname and second name are put into excel cells.
When Form 1 initializes the listview populates with this code:
VBA Code:
Private Sub UserForm_Initialize()
'Set some of the properties for the ListView
With Me.ListView1
.Gridlines = True
.HideColumnHeaders = False
.View = lvwReport
End With
'Call the sub to fill the ListView
Call LoadListView
End Sub
Sub LoadListView()
'Declare the variables
Dim wksSource As Worksheet 'Dim
Dim rngData As Range
Dim rngCell As Range
Dim LstItem As ListItem
Dim RowCount As Long
Dim ColCount As Long
Dim i As Long
Dim j As Long
'Clear list
Me.ListView1.ListItems.Clear
'Set the source worksheet
Set wksSource = Worksheets("settings")
'Set the source range
Set rngData = wksSource.Range("A1").CurrentRegion
'Add the column headers
For Each rngCell In rngData.Rows(1).Cells
Me.ListView1.ColumnHeaders.Add Text:=rngCell.Value, Width:=90 '# Me.ListView1
Next rngCell
'Count the number of rows in the source range
RowCount = rngData.Rows.Count
'Count the number of columns in the source range
ColCount = rngData.Columns.Count
'Fill the ListView
For i = 2 To RowCount
Set LstItem = Me.ListView1.ListItems.Add(Text:=rngData(i, 1).Value) '# Me.ListView1
For j = 2 To ColCount
LstItem.ListSubItems.Add Text:=rngData(i, j).Value
Next j
Next i
End Sub
On Form 2 when button is clicked, data is added to two cells, and trying to run the listview command again on Form 1 comes up with error: Run-time error '424'. Object required.
VBA Code:
Sub CommandButton1_Click()
NextEmptyRow = Sheets("settings").Cells(Rows.Count, "A").End(xlUp).Offset(1).Row
Sheets("settings").Cells(NextEmptyRow, "A").Value = TextBox1.Value
Sheets("settings").Cells(NextEmptyRow, "B").Value = TextBox2.Value
Form_Settings.LoadListView (anyVars)
Unload Me
End Sub
Been trying to fix this for a few days but most suggested is to use different Form options e.g. Forms!(formname) etc.. which is not working. Any help appreciated!