[RESOLVED] [2005] Pressing Cancel on InputBox
Has anyone came up with a solution on how to catch a blank entry or the cancel button being pressed. I have found a few posts on it but not resolution. Here's what I have. DateUp is of Date type. It errors out saying "" cannot be converted to date if I press cancel or leave it blank. Any ideas?
Code:
DateUp = InputBox("Please enter the date", "Date Needed")
If DateUp = "" Then
Exit Sub
End If
Re: [2005] Pressing Cancel on InputBox
Dont use InputBox, create your own custom form designed like an InputBox, and place a DateTimePicker control on it instead of a TextBox, call it with ShowDialog.
Re: [2005] Pressing Cancel on InputBox
Not a bad idea at all Atheist, I never thought of that. I may have to try that. I also found another way to make it not error out. I just used a try catch block and it works well too. Thanks for the input!
Quote:
Originally Posted by Atheist
Dont use InputBox, create your own custom form designed like an InputBox, and place a DateTimePicker control on it instead of a TextBox, call it with ShowDialog.
Re: [RESOLVED] [2005] Pressing Cancel on InputBox
You shouldn't use a Try Catch block to control your program flow. If you know that a blank value screws you up, code for that. You can take the input from the InputBox into a string and then use the DateTime.TryParse method to see if it is a valid date. If you do this, it will handle the blank scenario, but it will also handle the scenario if someone types in "AAAA".