VBA/Excel Crash After Subsequent Open

Cscott0685

New Member
Joined
Jan 4, 2018
Messages
2
Long code short, I've created an ERP system for tracking shelf life for materials. The open sequence is as follows:

On Workbook Object
Code:
[SIZE=2][SIZE=2][FONT=arial][COLOR=#000000][LEFT][COLOR=#222222][FONT=arial]Private Sub Workbook_Open() [/FONT][/COLOR]

[SIZE=2][COLOR=#222222][FONT=arial][COLOR=#000000]     Sheets("Lists").Visible = True[/COLOR][/FONT][/COLOR][/SIZE]
[/LEFT]
    Sheets("Materials").Visible = True[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=arial][COLOR=#000000]     Sheets("CurrentMaterial").Visible = True[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=arial][COLOR=#000000]     Sheets("Calendar").Visible = True[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=arial][COLOR=#000000]     Sheets("Passwords").Visible = True[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=arial][COLOR=#000000]     Sheets("LogSheet").Visible = True[/COLOR][/FONT][/SIZE]

[SIZE=2][FONT=arial][COLOR=#000000]    Application.Wait (Now +TimeValue("0:00:05"))[/COLOR][/FONT][/SIZE]

[SIZE=2][FONT=arial][COLOR=#000000]    UserForm_Login.Show[/COLOR][/FONT][/SIZE]
[/SIZE][FONT=arial][SIZE=2]End Sub
[/SIZE][/FONT]


On UserForm_Login Form
Code:
Private Sub UserForm_Initialize()
     Application.DisplayAlerts = False
     UserForm_Login.StartUpPosition = 2
End Sub

There is a textbox for user initials entry, and a "Login" button. Login Button checks for user existence, if exists, then...
.......
Code:
Else
     Me.OperItlsTextBox.Value = Null
     A[COLOR=#222222]pplication.WindowState = xlMinimized
[/COLOR][LEFT][COLOR=#222222]     UserForm_Main.Show
[/COLOR][/LEFT]
   End If
    Unload UserForm_Login
End Sub

On UserForm_Main Form
Code:
[LEFT][COLOR=#222222][FONT=arial]Sub UserForm_Initialize[/FONT][/COLOR][/LEFT]
     [FONT=arial][SIZE=2][COLOR=#000000]Application.DisplayAlerts = False[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]      With UserForm_Main[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]        .Width =Application.Width[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]        .Height =Application.Height[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]        .Top = 0[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]        .Left = -8[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]        .StartUpPosition = 3[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]End With[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][LEFT][COLOR=#222222][LEFT][COLOR=#222222][FONT=arial]     'Set up TreeView, Show/Hide Command Buttons, Run "Material Remove" Macro, etc.[/FONT][/COLOR][/LEFT]
End Sub
[/COLOR][/LEFT]
[/SIZE][/FONT]


All in-between functions perform as expected, no issues when working with the forms.

The Close sequence, initiated by clicking the "Exit" command button, is as follows:
Code:
[FONT=arial][SIZE=2][COLOR=#000000]
Sub ExitCommandButton()[/COLOR][/SIZE][/FONT]

[FONT=arial][SIZE=2][COLOR=#000000]        If MsgBox("ExitProgram?", vbYesNo) = vbYes Then[/COLOR][/SIZE][/FONT]

[FONT=arial][SIZE=2][COLOR=#000000]            UserForm_Main.Hide[/COLOR][/SIZE][/FONT]

[FONT=arial][SIZE=2][COLOR=#000000]           Sheets("Lists").Visible = False[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]           Sheets("Materials").Visible = False[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]            Sheets("CurrentMaterial").Visible= False[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]           Sheets("Calendar").Visible = False[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]           Sheets("Passwords").Visible = False[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]            Sheets("LogSheet").Visible = False[/COLOR][/SIZE][/FONT]

[FONT=arial][SIZE=2][COLOR=#000000]            Application.Wait (Now+ TimeValue("0:00:05"))[/COLOR][/SIZE][/FONT]

[FONT=arial][SIZE=2][COLOR=#000000]            ActiveWorkbook.Save[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]            Application.Wait (Now+ TimeValue("0:00:05"))[/COLOR][/SIZE][/FONT]
[FONT=arial][SIZE=2][COLOR=#000000]            Application.Quit[/COLOR][/SIZE][/FONT]

[FONT=arial][SIZE=2][COLOR=#000000]        End If[/COLOR][/SIZE][/FONT]

[FONT=arial][SIZE=2][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]


The "Application.Wait" was my attempt to allow Excel time to "catch up", hoping it would eliminate the issue.

This entire sequence (opening and closing) functions exactly as expected the first time I run through it.
After I click the "Exit" button, and allow the program to close, I start the sequence again from scratch (reopen the file).
The second time I open the file, it makes it to the Login form opening, I enter my initials, and click "Login", and that's where it crashes.
This makes absolutely no sense to me. If it functions as expected the first time through, I don't understand why it would crash the next time around.

Anyone have any insight as to what might be causing this? I've looked into "resetting" everything before (or after) opening (or closing), and couldn't find much information.

My goal is to:

Open the workbook
Load the Login UserForm
On correct login, load the Main UserForm
Make the Excel workbook minimized
'(do lots of stuff in between)

On "Exit" Click:
Hide the critical sheets in the workbook
Save the workbook
Exit Excel (not just unload the userform)

Thanks in advance!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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