Solved

VB6 validate if date exist

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now