?
Solved

VB6 validate if date exist

Posted on 2013-06-24
2
Medium Priority
?
470 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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

752 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