Solved

VB6 validate if date exist

Posted on 2013-06-24
2
450 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 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