How to code cancel button in InputBox

K1600

Board Regular
Joined
Oct 20, 2017
Messages
166
I have the below code which opens two inputbox's individually for to/from dates to be entered to run a report. Currently if the cancel button is pressed it closes everything down and reopens my login userform. Is it possible to code the cancel button to load a specific userform instead? Thanks in advance.

VBA Code:
'Gets input boxes for to/from dates for report
1 ans1 = InputBox("Enter Start Date", "Admin Dashboard", "dd/mm/yyyy")
    If ans1 = "" Then
        Exit Sub
    ElseIf IsDate(ans1) Then
        startdate = CDate(ans1)
    Else
    MsgBox "Please enter a valid start date"
    GoTo 1
    End If

2 ans2 = InputBox("Enter End Date", "Admin Dashboard", "dd/mm/yyyy")
    If ans2 = "" Then
        Exit Sub
    ElseIf IsDate(ans2) Then
        enddate = CDate(ans2)
    Else
    MsgBox "Please enter a valid end date"
    GoTo 2
    End If
 

Some videos you may like

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.

K1600

Board Regular
Joined
Oct 20, 2017
Messages
166
Cancel - I've sussed it!

In case anyone else struggles and stumbles across this thread, I just needed to add UsrFrmAdminDashboard.show after my If ans2 = "" Then and before Exit Sub.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,205
Messages
5,623,364
Members
415,969
Latest member
Rey99

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