How to code cancel button in InputBox

K1600

Board Regular
Joined
Oct 20, 2017
Messages
178
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
 

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.

K1600

Board Regular
Joined
Oct 20, 2017
Messages
178
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,013
Messages
5,834,927
Members
430,326
Latest member
tomwax46

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