Solved

VB6 validate if date exist

Posted on 2013-06-24
2
456 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

685 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