Solved

VB6 validate if date exist

Posted on 2013-06-24
2
459 Views
Last Modified: 2013-06-24
Hi all,

I would like to validate if all dates in column 12 of my MSHFlexgrid.

The thing is that the dates have this format: yyyymmdd
Ex:20130631

in the example above, June 2013 end on day 30, not 31.

When it found a date that does not exist, it will put on column 1 of the same row "date not valid"

How can i do that?

Thanks again for your help
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39271432
Here is one way:
Sub Validate()
Dim strDate As String
Dim dt As Date

strDate = "20130631"
dt = DateSerial(CInt(Mid(strDate, 1, 4)), CInt(Mid(strDate, 5, 2)), CInt(Mid(strDate, 7, 2)))
If strDate = Format(dt, "yyyymmdd") Then
    MsgBox "Date is valid"
Else
    MsgBox "Date is not valid"
End If
End Sub

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39271619
Hi

Many thanks.

This is perfect

  Dim strDate As String
    Dim dt As Date
    Dim i As Long
    For i = 1 To MSHFlexGrid1.Rows - 1

        strDate = MSHFlexGrid1.TextMatrix(i, 12)
        dt = DateSerial(CInt(Mid(strDate, 1, 4)), CInt(Mid(strDate, 5, 2)), CInt(Mid(strDate, 7, 2)))
        If strDate = Format(dt, "yyyymmdd") Then

        Else
            MSHFlexGrid1.TextMatrix(i, 1) = MSHFlexGrid1.TextMatrix(i, 1) & " / " & "BAD EFFECTIVE DATE"
        End If
Next
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question