Userform opens another userform - Excel crashes

dcarsonx

New Member
Joined
Dec 20, 2016
Messages
2
Hello,

I'm hoping to get help with the following challenge (man - I appreciate this forum!)

I will provide the user's sequential steps, problem statement, hypothesis, and then the code.

Usability Steps:
1. User opens .xlsm file (there are about 15 users in which each has their own unique copy; the only difference between each copy is the filename)
2. A Userform (named Userform2) opens once the file opens.
3. Userform2 has two control buttons: (a) first control button opens a userform called Userform1; and (b) the second control button opens a different userform called Userform3
4. Once the user clicks either control button a Msgbox to receive a password appears and if the user correctly enters the password, the respective userform opens (either Userform1 or Userform3) and Userform2 closes.

Problem Statement: In a limited set of users, Excel will crash when the user selects either control button or after the user enters the password and selects "OK". Excel will provide the following message:
(1) Microsoft has stopped working...; then (2) Excel offers an option to check online for a solution and then shuts down (no solution is provided).

Hypothesis: A conflict occurs in which one Userform is attempting to close while another Userform is attempting to open.

Code:

A. The following code is used under Microsoft Excel Objects > This Workbook (this code launches Userform2)

Private Sub Workbook_Open()
Application.WindowState = xlMaximized
ActiveSheet.Protect , UserInterfaceOnly:=True
UserForm2.Show vbModeless
End Sub

B. The following code is used under Forms > UserForm2 (this code checks the password and if correct, opens the respective userform)

Private Sub fmcobu1accountmanager_Click()

Dim Res As String
Const PWORD As String = "XXXXXX"


Res = InputBox(Prompt:="Enter password")


If Res <> PWORD Then
MsgBox Prompt:="The password has not " _
& "been recognized!", _
Buttons:=vbCritical, _
Title:="Password"
Exit Sub
End If


Unload UserForm2


ThisWorkbook.Save 'Without this line Excel crashes for all users


UserForm1.Show


End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub fmcobu2fae_Click()


Dim Res As String
Const PWORD As String = "YYYYYYY"


Res = InputBox(Prompt:="Enter password")


If Res <> PWORD Then
MsgBox Prompt:="The password has not " _
& "been recognized!", _
Buttons:=vbCritical, _
Title:="Password"
Exit Sub
End If


Unload UserForm2


ThisWorkbook.Save 'Without this line Excel crashes for all users


UserForm3.Show


End Sub



Please help and THANK YOU!!!

DC
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Have no idea. Did you try to write a new sub, with something like :
Code:
Sub OpenUserForm(ByVal Num As Integer)
Select Case Num
Case 1
    UserForm1.Show
Case 3
    UserForm3.Show
End Select

End Sub

And if you don't do anything after "Unload UserForm2", does it crash?
 
Last edited:
Upvote 0
Thank you for the quick reply! Your comment made me think a bit further... Rather than closing Userform2, I can leave it open which does work and does not cause Excel to crash. However, I need to do further testing with users. I will update this post once I close end user testing. I appreciate your response!
 
Upvote 0

Forum statistics

Threads
1,214,962
Messages
6,122,482
Members
449,088
Latest member
Melvetica

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