Z
zz
i have this code in a userform called view_employees
now in my code i want to display a list that i keep in a sheet named
"empleados"
if range "a2" is empty i want to hide the listview i use to display the
list and display a simple label with a message about no employees to show
if i have values in the cell it runs ok, with the help of some folks in the
spanish newsgroups it even runs faster, but when there are no values in the
cell ["a2"], it makes excel to crash.
i look at the code and know there are better ways to do this, but it was
working before, i just changed the validation of the value of cell a2 and
instead of doing it in the load_list sub y changed it to not even run the
load_list sub if the cell value is blank, but it still crashes.
and sincerely dont know where the hook may be!!!
i really really need help...
---- here's my code ---
Private Sub Lbladd_new_Click()
' this is label is used to call a userform used to add a
new employee
add_employee.Show
End Sub
Private Sub load_list()
' this loads the list of employees in a listview
On Error GoTo errhandler
Me.listempleados.ListItems.Clear ' so we do not get duplicated
entries
With Sheets("empleados")
Dim indx As Integer
indx = 1
Do Until Range("A" & indx).Value = ""
Me.listempleados.ListItems.Add indx, , .Range("A" &
indx).Offset(1, 1).Value 'numero de empleado
Me.listempleados.ListItems(indx).ListSubItems.Add , ,
Range("A" & indx).Offset(1, 2).Value 'nombre
Me.listempleados.ListItems(indx).ListSubItems.Add , ,
Range("A" & indx).Offset(1, 3).Value 'ap paterno
Me.listempleados.ListItems(indx).ListSubItems.Add , ,
Range("A" & indx).Offset(1, 4).Value 'ap materno
Me.listempleados.ListItems(indx).ListSubItems.Add , ,
Range("A" & indx).Offset(1, 5).Value 'entrenador
indx = indx + 1
Loop
End With
errhandler:
Exit Sub
End Sub
Private Sub LblRefresh_Click()
' once a employee is added this label refreshes the listview
contents
load_list
End Sub
Private Sub UserForm_Initialize()
' here is where i changed the validation
If Sheets("empleados").Range("a2").Value = "" Then
Me.listempleados.Visible = False
Else
load_list
End If
End Sub
i suspect the if clausule in the userform initialize part is not doing it's
job, and it tries to load the entire column values but i'm just guessing.
BTW: sorry by all spanglish in the code, but there are some variable name i
remember the best in english and other i do remember better in spanish.
now in my code i want to display a list that i keep in a sheet named
"empleados"
if range "a2" is empty i want to hide the listview i use to display the
list and display a simple label with a message about no employees to show
if i have values in the cell it runs ok, with the help of some folks in the
spanish newsgroups it even runs faster, but when there are no values in the
cell ["a2"], it makes excel to crash.
i look at the code and know there are better ways to do this, but it was
working before, i just changed the validation of the value of cell a2 and
instead of doing it in the load_list sub y changed it to not even run the
load_list sub if the cell value is blank, but it still crashes.
and sincerely dont know where the hook may be!!!
i really really need help...
---- here's my code ---
Private Sub Lbladd_new_Click()
' this is label is used to call a userform used to add a
new employee
add_employee.Show
End Sub
Private Sub load_list()
' this loads the list of employees in a listview
On Error GoTo errhandler
Me.listempleados.ListItems.Clear ' so we do not get duplicated
entries
With Sheets("empleados")
Dim indx As Integer
indx = 1
Do Until Range("A" & indx).Value = ""
Me.listempleados.ListItems.Add indx, , .Range("A" &
indx).Offset(1, 1).Value 'numero de empleado
Me.listempleados.ListItems(indx).ListSubItems.Add , ,
Range("A" & indx).Offset(1, 2).Value 'nombre
Me.listempleados.ListItems(indx).ListSubItems.Add , ,
Range("A" & indx).Offset(1, 3).Value 'ap paterno
Me.listempleados.ListItems(indx).ListSubItems.Add , ,
Range("A" & indx).Offset(1, 4).Value 'ap materno
Me.listempleados.ListItems(indx).ListSubItems.Add , ,
Range("A" & indx).Offset(1, 5).Value 'entrenador
indx = indx + 1
Loop
End With
errhandler:
Exit Sub
End Sub
Private Sub LblRefresh_Click()
' once a employee is added this label refreshes the listview
contents
load_list
End Sub
Private Sub UserForm_Initialize()
' here is where i changed the validation
If Sheets("empleados").Range("a2").Value = "" Then
Me.listempleados.Visible = False
Else
load_list
End If
End Sub
i suspect the if clausule in the userform initialize part is not doing it's
job, and it tries to load the entire column values but i'm just guessing.
BTW: sorry by all spanglish in the code, but there are some variable name i
remember the best in english and other i do remember better in spanish.