Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Date Validation

Thanks in Advance for help.

i created a User Form with data box that collects the date in the
format of MMDDYYYY, i tried to validate the date with lots of code but
in the end i failed because i am a novice to VBA. i was wondering if
there is anyway to take above format and actually spit out something
like this MM/DD/YYYY, at the same time have some kind of validation so
that if the user put's all zero's and wrong format we can tell the
user to reenter the date. This code was used but it has it's defects.


Private Sub DateTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo DateError
Newdate = Format(DateTextBox.Text, "00000000")
varDate = Left(Newdate, 2) & "/" & Mid(Newdate, 3, 2) & "/" &
Right(Newdate, 2)
DateTextBox.Text = DateValue(varDate)
Exit Sub
DateError:
MsgBox "Date Error"
DateTextBox.Text = ""
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Date Validation

instead of a general "date error", maybe the msgbox should tell them
what format you WANT it in.

MsgBox "Date Error - date must be in mm/dd/yyyy format." _
& vbcrlf & _
"Please try again using the correct format."

otherwise the user just keeps inputting the wrong format & it keeps
kicking it out.
susan


On Feb 26, 3:19 pm, "Aravind" wrote:
Thanks in Advance for help.

i created a User Form with data box that collects the date in the
format of MMDDYYYY, i tried to validate the date with lots of code but
in the end i failed because i am a novice to VBA. i was wondering if
there is anyway to take above format and actually spit out something
like this MM/DD/YYYY, at the same time have some kind of validation so
that if the user put's all zero's and wrong format we can tell the
user to reenter the date. This code was used but it has it's defects.

Private Sub DateTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo DateError
Newdate = Format(DateTextBox.Text, "00000000")
varDate = Left(Newdate, 2) & "/" & Mid(Newdate, 3, 2) & "/" &
Right(Newdate, 2)
DateTextBox.Text = DateValue(varDate)
Exit Sub
DateError:
MsgBox "Date Error"
DateTextBox.Text = ""
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Date Validation

You may find your job as a programmer gets simpler if you use a calendar control
to get the date.

Ron de Bruin has some tips/links at:
http://www.rondebruin.nl/calendar.htm

And you wouldn't have to take a chance that 02032007 meant Feb 3rd, 2007 or
March 2nd, 2007.



Aravind wrote:

Thanks in Advance for help.

i created a User Form with data box that collects the date in the
format of MMDDYYYY, i tried to validate the date with lots of code but
in the end i failed because i am a novice to VBA. i was wondering if
there is anyway to take above format and actually spit out something
like this MM/DD/YYYY, at the same time have some kind of validation so
that if the user put's all zero's and wrong format we can tell the
user to reenter the date. This code was used but it has it's defects.

Private Sub DateTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo DateError
Newdate = Format(DateTextBox.Text, "00000000")
varDate = Left(Newdate, 2) & "/" & Mid(Newdate, 3, 2) & "/" &
Right(Newdate, 2)
DateTextBox.Text = DateValue(varDate)
Exit Sub
DateError:
MsgBox "Date Error"
DateTextBox.Text = ""
End Sub


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Validation for Date of Birth Stitch45 Excel Programming 2 March 5th 06 10:58 AM
Date Validation - Must equal Sundays date jeridbohmann Excel Discussion (Misc queries) 14 November 30th 05 08:40 PM
Date Colum Date Formatting & Validation Mike[_81_] Excel Programming 1 June 7th 04 01:59 AM
Date Validation Nigel[_5_] Excel Programming 5 October 30th 03 05:09 PM
date validation Jo[_4_] Excel Programming 1 October 20th 03 08:50 PM


All times are GMT +1. The time now is 09:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"