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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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