i have an editable mshflexgrid that a user can enter dates/times the app does calculations on these entries and need to make sure they are entered in the correct format

this fixes the date problem

this fixes the date problem

Private Sub YourSub()
Dim MyDate As String

MyDate = "11/15/896"

If IsDateEx(MyDate) Then
    MsgBox "Valid"
Else
    MsgBox "Not valid"
End If
End Sub

Private Function IsDateEx(strDate As String, Optional intSpan As Integer = 20) As Boolean

If IsDate(strDate) And Year(strDate) - intSpan <= Year(Now) And Year(strDate) + intSpan >= Year(Now) Then
    IsDateEx = True
Else
    IsDateEx = False
End If
End Function

Open in new window

Private Sub YourSub()
Dim MyDate As String

MyDate = "11/15/896"

If IsDateEx(MyDate) Then
    MsgBox "Valid"
Else
    MsgBox "Not valid"
End If
End Sub

Private Function IsDateEx(strDate As String, Optional intSpan As Integer = 20) As Boolean

If IsDate(strDate) And Year(strDate) - intSpan <= Year(Now) And Year(strDate) + intSpan >= Year(Now) Then
    IsDateEx = True
Else
    IsDateEx = False
End If
End Function
but now have aproblem with the time
this is valid by vb "14:36am"
but this not
"10:61am"
it seems the minutes are correct, but not the hours

how can yhis be corrected?
Private Sub YourSub()
Dim MyDate As String

MyDate = "11/15/896"

If IsDateEx(MyDate) Then
    MsgBox "Valid"
Else
    MsgBox "Not valid"
End If
End Sub

Private Function IsDateEx(strDate As String, Optional intSpan As Integer = 20) As Boolean

If IsDate(strDate) And Year(strDate) - intSpan <= Year(Now) And Year(strDate) + intSpan >= Year(Now) Then
    IsDateEx = True
Else
    IsDateEx = False
End If
End Function

Open in new window

date_time_format.jpg
isnoend2001Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
this is valid by vb "14:36am"
but this not
"10:61am"
10:61 is not a valid time, so vb is correct.

Why are you having people enter dates rather then picking them from a date picker control?
isnoend2001Author Commented:
The dates time are entered by datepicker, this gives the correct format, but i am trying to give the user the ability to change if neccessary. eg;
sisters doctor called and changed her app time from 1:30 to 3:30
tried to edit the question an put the proper code tags, but was denied
Martin LissOlder than dirtCommented:
I'm confused. If this is about appointment times, and the dates are entered by way of the datepicker, why did you ask about "11/15/896"?

Also you can change the datepicker to act as a timepicker by setting one of it's properties, so validating either the date or the time should not be an issue.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

isnoend2001Author Commented:
vb says this is valid
"14:36am"
should this be PM to be valid ?
Martin LissOlder than dirtCommented:
14:36 should not show either am or pm. It's 24-hour (military) time and it is understood that that's an afternoon time.
isnoend2001Author Commented:
after more thought in the am/pm format
the bours can never be  more than 12
isnoend2001Author Commented:
I want to force the user to enter am/pm time
Martin LissOlder than dirtCommented:
Use the datepicker and set the Format property to dtpTime which is 2.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isnoend2001Author Commented:
Thanks
I guess, if the grid expects a time instead of allowing edit i could open date picker
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.