Userform Freezing Intermittantly

TheRobRush

New Member
Joined
Nov 5, 2018
Messages
39
I have a couple userforms with very similar code, see below for an example.

The problem with them is occasionally excel freezes as they are opened right before the form is displayed.

Pressing ctrl-alt-del and close excel pops up with a cannot close excel waiting for response/input from you.
If you cancel the closing at this point, then repeat that step one more time after the second cancel the form is loaded and ready to go. VERY strange.

hoping someone can see an error below that would be causing this. Including my public variables page, and the forms initialize data...

Public decl
Code:
Option Explicit
Public MillaJovavich As String

Public AnnaKendrick As String

Public NextDayStart As Boolean

Public NextDayEnd As Boolean


USERFORM INIT
Code:
Private Sub Userform_Initialize()

Application.EnableEvents = False
Application.Calculation = xlCalculationManual

    Dim hr As Long
    Dim hr2 As Long
    Dim d As Date
 '   Dim min As Long
 '   Dim min2 As Long
    Dim TK_min As String
    Dim Squirtle, Bulbasaur, Charmander

    d = Now()
   
    Application.ScreenUpdating = False
    
    Label6.Caption = "Dispatching: " & ActiveSheet.Range("A" & Selection.row).Value
    
    ' & " " & ActiveSheet.Range("F" & Selection.row).Value

    
    hr = Left(Format(Now(), "HH:MM"), 2)
    
    min = Right(Format(Now(), "HH:MM"), 2)
    
    hr2 = Left(Format(Now(), "HH:MM"), 2)
    
    min2 = Right(Format(Now(), "HH:MM"), 2)
    
    '====================== CHECK 24 HOUR ROLLOVER
'==========STEP 1 DONE
MsgBox "CHECKPOINT 1"
'==========STEP 1 DONE

 If hr = 23 And min >= 45 Then
 NextDayStart = True
 Else
 NextDayStart = False
 End If
 
'==========STEP 1 DONE
MsgBox "CHECKPOINT 2"
'==========STEP 1 DONE
    '=============== CHANGE MILITARY TIME TO NORMAL TIME
    
    If hr = 24 Or hr <= 11 Then
    MillaJovavich = "AM"
    ElseIf hr >= 13 Then
    hr = hr - 12
    MillaJovavich = "PM"
    ElseIf hr = 12 Then
    MillaJovavich = "PM"
    End If
'==========STEP 1 DONE
MsgBox "CHECKPOINT 3"
'==========STEP 1 DONE
   If hr = 0 Then
   hr = 12
   ElseIf hr = 24 Then
   hr = 12
   Else
   hr = hr
   End If
 '==========STEP 1 DONE
MsgBox "CHECKPOINT 4"
'==========STEP 1 DONE
   '=============== CONTINUED - END TIME
   
   
    If hr2 = 24 Or hr2 <= 11 Then
    AnnaKendrick = "AM"
    ElseIf hr2 >= 13 Then
    hr2 = hr2 - 12
    AnnaKendrick = "PM"
    ElseIf hr2 = 12 Then
    AnnaKendrick = "PM"
    End If
'==========STEP 1 DONE
MsgBox "CHECKPOINT 5"
'==========STEP 1 DONE
   If hr2 = 0 Then
   hr2 = 12
   ElseIf hr2 = 24 Then
   hr2 = 12
   Else
   hr2 = hr2
   End If
 '==========STEP 1 DONE
MsgBox "CHECKPOINT 6"
'==========STEP 1 DONE
   '=============== END FORMAT CONVERSION
    
   
   '=============== ADD 0 TO MINUTES TAKEN AWAY
   
   
   ' If min < 10 Then
   ' min = "0" & min
   ' End If
   '
   ' If min2 < 10 Then
   ' min2 = "0" & min2
   ' End If
  
 '=============== SET SELECTABLE TIMES
 
    Dim call_times_hr As Variant
    ReDim call_times_hr(24)
    call_times_hr = Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "00")
    ComboBox1.ColumnCount = 1
    ComboBox3.ColumnCount = 1
    ComboBox1.List() = call_times_hr
    ComboBox3.List() = call_times_hr
    ComboBox1.Value = hr
    ComboBox3.Value = hr2

    Dim call_times_min As Variant
    ReDim call_times_min(10)
    call_times_min = Array("00", "06", "12", "18", "24", "30", "36", "42", "48", "54")
    ComboBox2.ColumnCount = 1
    ComboBox4.ColumnCount = 1
    ComboBox2.List() = call_times_min
    ComboBox4.List() = call_times_min
 '===============
  '  If min < 10 Then
  '  min = "0" & min
  '  End If
  '
  '  If min2 < 10 Then
  '  min2 = "0" & min2
  '  End If

'==========STEP 1 DONE
MsgBox "CHECKPOINT 7"
'==========STEP 1 DONE

    ComboBox2.Value = min
    
    If min + 15 >= 60 Then
    min2 = min + 15 - 60
    hr2 = hr2 + 1
    ComboBox4.Value = min2
    ComboBox3.Value = hr2
    Else
    ComboBox4.Value = min + 15
    End If
    
  '  If min2 < 10 Then
  '  min2 = "0" & min2
  '  End If
    
    
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hello RTheRobRush,

Remove the Application.EnableEvents = False statement. The UserForm requires events be enabled to properly communicate with Excel.
 
Upvote 0
thanks for that, will remove it.

added this during testing looking for the error though, so will not get rid of it unfortunately
 
Upvote 0

Forum statistics

Threads
1,216,086
Messages
6,128,736
Members
449,466
Latest member
Peter Juhnke

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