Hi, this is the first time I have posted on this wonderful source of info, so be gentle with me.
I am designing a form based tool which involves entering quite a lot of data on to a workbook, using vba forms.
I am using lots of expressions like
worksheets("Milestones").cells(SelectionRow, 21).value=cdate(txtDeadline.text)
I am also using an error handling procedure to ensure that only dates are entered, like:
on error goto DateError
...
unload me
goto finish:
DateError:
msgbox("One of the values entered is not a valid date. Please check and try again.")
finish:
This works perfectly except for the fact that if a text box is left blank on the form, you get the same error. I.e. Cdate operating on a blank string gives the same error.
The obvious (in my eyes) solution is wherever I use Cdate to create a function e.g. ConvertDate as follows:
function ConvertDate(date_to_convert)
if date_to_convert="" then goto continue
convertdate=cdate(date_to_convert)
continue:
end function
Can anyone think of a more elegant/better solution to my dilemma.
I need some sort of validation on the dates entered via the form, but need the ability for text boxes to be left blank at times too.
Thanks
Gopes
P.S. Apologies for poor formatting - cannot download programs such as VB HTML Maker at work
I am designing a form based tool which involves entering quite a lot of data on to a workbook, using vba forms.
I am using lots of expressions like
worksheets("Milestones").cells(SelectionRow, 21).value=cdate(txtDeadline.text)
I am also using an error handling procedure to ensure that only dates are entered, like:
on error goto DateError
...
unload me
goto finish:
DateError:
msgbox("One of the values entered is not a valid date. Please check and try again.")
finish:
This works perfectly except for the fact that if a text box is left blank on the form, you get the same error. I.e. Cdate operating on a blank string gives the same error.
The obvious (in my eyes) solution is wherever I use Cdate to create a function e.g. ConvertDate as follows:
function ConvertDate(date_to_convert)
if date_to_convert="" then goto continue
convertdate=cdate(date_to_convert)
continue:
end function
Can anyone think of a more elegant/better solution to my dilemma.
I need some sort of validation on the dates entered via the form, but need the ability for text boxes to be left blank at times too.
Thanks
Gopes
P.S. Apologies for poor formatting - cannot download programs such as VB HTML Maker at work