I have the following code in a larger piece of coding which basically runs a report between two selected dates. I want to keep the current setup but also create an error if the second date (ans2) is before the first (ans1). I don't mind if I have to create a combined error message for an invalid date and also dates in the wrong order if that makes it easier to resolve.
Thanks in advance.
Thanks in advance.
VBA Code:
Private Sub CmdRunReport_Click()
Dim wbk1 As Workbook
Dim sht1 As Worksheet
Dim wbk2 As Workbook
Dim sht2 As Worksheet
Dim startdate As Date, enddate As Date
Dim rng As Range, destRow As Long
Dim c As Range
Dim ans1 As String, ans2 As String
Application.ScreenUpdating = False 'Stops screen showing during process
'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
'The rest of the coding for running the report follows from here......