![]() |
Check on the input in an inputbox
Could somebody please help me with some code to be able to check the date format the user puts into an input box. I need to compare two dates and get the amount of days, so they need to enter the date as 2004/01/14 and i need to confirm that it has been entered correctly, if not return to the beginning & re-enter. Les Stout *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
Check on the input in an inputbox
Hi Les,
Here's some code that should work: Public Function gbIsValidDate(rsDate As String) As Boolean Dim avDate As Variant If IsDate(rsDate) Then avDate = Split(rsDate, "/") If UBound(avDate) = 2 Then gbIsValidDate = Len(avDate(0)) = 4 _ And Len(avDate(1)) = 2 _ And Len(avDate(2)) = 2 End If End If End Function Sub test() Dim sDate As String Dim bValid As Boolean Do While Not bValid sDate = InputBox$("Please enter a date in " _ & "yyyy/mm/dd format", "Enter Date", _ Format$(Date, "yyyy/mm/dd")) bValid = gbIsValidDate(sDate) Loop End Sub It's not elegant, but it should force the user to enter a date in yyyy/mm/dd format before the code proceeds. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Les Stout wrote: Could somebody please help me with some code to be able to check the date format the user puts into an input box. I need to compare two dates and get the amount of days, so they need to enter the date as 2004/01/14 and i need to confirm that it has been entered correctly, if not return to the beginning & re-enter. Les Stout *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
Check on the input in an inputbox
Thanks Jake, much appreciated
Les Stout *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
All times are GMT +1. The time now is 05:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com