Userform not opening from second time

JOHNLEO

New Member
Joined
May 21, 2021
Messages
1
Office Version
  1. 2019
Hi, There is a form that opens when i open the workbook and workbook is hidden (only shows Userform not the workbook when opens)
This userform i created has A TEXT BOX and two buttons CONTINUE and CANCEL.
If i hit CONTINUE, something should happen and then open the workbook
If i hit CANCEL, then it should close the workbook.
CANCEL button working fine only for the first time, if i try to open the workbook again, directly its showing workbook without userform.
If i close and open the workbook again, then its working fine (only userform, and workbook ishidden).
So every second time, the workbook opening without showing userform if the previous time i hit CANCEL

VBA Code:

VBA Code:
Private Sub CONTINUE_Click()
    ThisWorkbook.Sheets("MAIN").[B1].Value = Select_System.Value
    ThisWorkbook.Sheets("MAIN").[B2].Value = Select_Frame.Value
    ThisWorkbook.Sheets("MAIN").[B3].Value = Select_Grate.Value

If ThisWorkbook.Sheets("MAIN").[B1].Value = "" Then
    RESULT = MsgBox("INVALID INPUT", vbRetryCancel + vbCritical)
        If RESULT = vbCancel Then
            Unload FloThru
            Application.Quit
            ThisWorkbook.Save = False
        End If
Else
    Application.Visible = True
    Unload FloThru
End If
End Sub

Private Sub CANCEL_Click()
Unload FloThru

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,867
Office Version
  1. 2016
Platform
  1. Windows
Your Cansel only unload userform but not closing workbook. I guess the Workbook Open will not trigger to show userform since it is still open but hidden
 

vw412

Active Member
Joined
Dec 16, 2011
Messages
343
Office Version
  1. 2019
  2. 2016
  3. 2010
  4. 2007
Platform
  1. Windows
Here is a rework of your code that might work for you:
VBA Code:
Option Explicit
Private Sub CONTINUE_Click()
    ThisWorkbook.Sheets("MAIN").[B1].Value = Select_System.Value
    ThisWorkbook.Sheets("MAIN").[B2].Value = Select_Frame.Value
    ThisWorkbook.Sheets("MAIN").[B3].Value = Select_Grate.Value

If ThisWorkbook.Sheets("MAIN").[B1].Value = "" Then
    RESULT = MsgBox("INVALID INPUT", vbRetryCancel + vbCritical)
        If RESULT = vbCancel Then
            Unload FloThru
            ThisWorkbook.Save = False
            Application.Visible = True
            Application.Quit
        End If
Else
    Application.Visible = True
    Unload FloThru
End If
End Sub

Private Sub CANCEL_Click()
    Unload FloThru
    ThisWorkbook.Save = False
    Application.Visible = True
    Application.Quit
End Sub
 

Forum statistics

Threads
1,147,735
Messages
5,742,869
Members
423,760
Latest member
photogfrog

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
Top