Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2006, 07:48 AM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Validate date format is correct

Hi,

I am a beginer to VBA,
so this is my question :

When i input a date in xls cell (which has a formatting set to date Eg : 14-Mar-99) , i need to check if date is in the range 1 - 31, month should be in the range 1-12 , and year should be in the range 1906-2106.

i used the follwing condition :
variable dt is the date i am getting from the xls cell.
For Year:
If CInt(Year(dt)) < 1906 Or CInt(Year(dt)) > 2106 Then
    display error
For month:
If CInt(Month(dt)) < 1 Or CInt(Month(dt)) > 12 Then
    display error
for day:
If CInt(Day(dt)) < 1 Or CInt(Day(dt)) > 31 Then
    display error

When i enter valid date , this works fine.
But, when i enter a invalid value in xls cell eg :32/12/378373 , i get a type Run time Error : 13
Type Mismatch.

Is this the right way to check? And am i getting Type mismatch because the cell's format is of type date?

Should i just catch the Type mismatch error for "invalid date"?


Thanks,
Gayatri





Similar Threads
Thread Thread Starter Forum Replies Last Post
input string not in correct format sarah lee ASP.NET 1.0 and 1.1 Basics 10 October 30th, 2006 05:18 PM
Input string was not in a correct format. palleti VB.NET 2002/2003 Basics 2 October 17th, 2006 10:38 AM
Input string was not in a correct format. Silfverduk VB.NET 2002/2003 Basics 1 May 20th, 2006 04:58 AM
"Input string was not in a correct format." keane Pro VB.NET 2002/2003 1 December 18th, 2004 08:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.