View Single Post
 
Old 04-03-2022, 03:14 AM
CuriousG CuriousG is offline Windows 10 Office 2016
Novice
 
Join Date: Jan 2021
Posts: 20
CuriousG is on a distinguished road
Default Error handling input to a Date variable

I have the following statements in my code:

DueDate = InputBox("Enter the date the payment is due in format dd/mm/yyyy")
Do Until DateValue = DueDate
Charge = Charge + 1
RunningTotal = RunningTotal + Charge
DateValue = DateValue + 1
Loop

It performs as expected when an appropriate value is assigned to the variable DueDate but fails under the following circumstances:
1. No value is entered in InputBox and OK is pressed
2. No value is entered in InputBox and Cancel is pressed
3. No value is entered in InputBox and the box is closed by clicking on the X
In each of the above cases the value 00:00:00 is assigned to the variable DueDate.

There is also some unexpected outcome if the value entered in the variable DueDate precedes that held in DateValue.

Whilst I sort of understand (a little bit) what's going on here, I can't figure out how to construct the appropriate error handling statements to cater for these 4 fail scenarios.

Grateful for any advice please.
Reply With Quote