PC Review


Reply
Thread Tools Rate Thread

this code makes excel crash

 
 
zz
Guest
Posts: n/a
 
      22nd Dec 2006
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.



--
---
zz [MX]
cuasi-musico,semi-poeta y loco


 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      23rd Dec 2006

Do you have a reference set in Excel to Comctl32.ocx?

They may have been just omitted from the post, but every use of
Range should have a dot "." in front of it.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"zz" <(E-Mail Removed)>
wrote in message
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.



--
---
zz [MX]
cuasi-musico,semi-poeta y loco


 
Reply With Quote
 
zz
Guest
Posts: n/a
 
      23rd Dec 2006
nope it still crashes,

i added the reference to comctl32.ocx, but i still get the same results, the
dots were not ommited only for the post, but the code was working even
without them, and now it crashes even with data in range "a2"





"Jim Cone" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Do you have a reference set in Excel to Comctl32.ocx?
>
> They may have been just omitted from the post, but every use of
> Range should have a dot "." in front of it.
> --
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware
>
>
>
> "zz" <(E-Mail Removed)>
> wrote in message
> 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.
>
>
>
> --
> ---
> zz [MX]
> cuasi-musico,semi-poeta y loco
>
>



 
Reply With Quote
 
zz
Guest
Posts: n/a
 
      23rd Dec 2006
this correction did the trick

this time i don hide the listview, instead i make it too thin, and voilá.

hope someone finds this useful.


Private Sub load_list()
On Error GoTo errhandler
Me.listempleados.ListItems.Clear
With Sheets("empleados")
Dim indx As Integer
indx = 1
If .Range("a" & indx + 1).Value = "" Then
listempleados.Width = 0
Else
Do Until .Range("A" & indx).Value = ""
Me.listempleados.ListItems.Add indx, , .Range("A" &
indx).Offset(1, 1).Value 'numero
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 If
End With
errhandler:
Exit Sub
End Sub


--
---
zz [MX]
cuasi-musico,semi-poeta y loco


 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      23rd Dec 2006
The dot in front of "range" connects it to the sheet in the
With statement. Otherwise "range" will refer to the active sheet.

There are too many possible things that could be wrong with the
code for me to make any further suggestions.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"zz" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
nope it still crashes,
i added the reference to comctl32.ocx, but i still get the same results, the
dots were not ommited only for the post, but the code was working even
without them, and now it crashes even with data in range "a2"





"Jim Cone" <(E-Mail Removed)>
wrote in message
> Do you have a reference set in Excel to Comctl32.ocx?
>
> They may have been just omitted from the post, but every use of
> Range should have a dot "." in front of it.
> --
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware
>
>
>
> "zz" <(E-Mail Removed)>
> wrote in message
> 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.
> zz [MX]
> cuasi-musico,semi-poeta y loco


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What in the edited code below makes it crash????? Simon Microsoft Excel Programming 2 13th Aug 2008 04:26 PM
Simple code makes Excel 2007 crash Mathieu Microsoft Excel Programming 6 10th Apr 2008 09:56 AM
Execution of code makes a Windows 2003 server crash completely Russell Microsoft Dot NET 0 25th Feb 2004 04:29 PM
This piece of code still makes IE crash! Why hasn't MS fixed? Robert Gustavsson Windows XP Internet Explorer 1 15th Dec 2003 07:39 PM
Crystal report in Excel format makes Excel crash =?Utf-8?B?T0c=?= Microsoft Excel Crashes 0 30th Oct 2003 12:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 AM.