How to code cancel button in InputBox

K1600

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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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