Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 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 March 16th, 2006, 06:15 PM
Authorized User
 
Join Date: Mar 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to give Date format while entering date

hi!
I m trying to use a format dd/mm/yyyy for entering date in textbox. If user enters format other than dd/mm/yyyy, as soon as the textbox losts its focus it gives a msg to user to enter date in correct format. I tried using following code but even if i give correct format it gives same msg as if it is not incorrect format.
Could anyone be able to correct it plz..

Private Sub txtDob_LostFocus()
If txtDob.Text <> "dd'/ 'MM' / 'yyyy" Then

MsgBox "Please! Mention the date of birth in dd/mm/yyyy format", vbInformation
txtDob.SetFocus
SendKeys "{Home}+{End}"

End If
End Sub

 
Old March 17th, 2006, 12:01 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default



Use this....

MsgBox Format("10-11-06", "dd-mmm-yyyy")

Deepak..
 
Old March 17th, 2006, 04:14 AM
Authorized User
 
Join Date: Mar 2006
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Ana

your condition: If txtDob.Text <> "dd'/ 'MM' / 'yyyy" Then means that:
user must wrote exact phrase "dd'/ 'MM' / 'yyyy" in textbox if he want to get correct behaviour of this condition. Other types means, that he see the message box.
Try to use the mask (like Access textbox) in this textbox (if you can), then will be great.

Peko

 
Old March 17th, 2006, 06:39 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

hi anju

use this code

Private Sub Text1_Validate(Cancel As Boolean)
    If IsDate(Format(Text1.Text, "dd/MMM/yyyy")) = False Then
        MsgBox "Error Message"
    End If
End Sub


i hope it will solve ur prob



Cheers :)

Ashu


 
Old March 17th, 2006, 07:25 AM
Authorized User
 
Join Date: Mar 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Ashu!!

Thanx for ur help
Your code works for validating the date if user enters characters on date of birth but if i put numbers e.g. 132435 in the textbox it accepts it and ignores the function.
any clue why is this happening?

thanx
anju






Similar Threads
Thread Thread Starter Forum Replies Last Post
date format differs, need to force format somehow patricolsson ASP.NET 2.0 Basics 1 December 3rd, 2009 12:53 AM
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
date format differs, need to force format somehow patricolsson HTML Code Clinic 2 January 12th, 2006 05:55 AM
entering Null value for Date field jordancrandall Access ASP 1 January 12th, 2005 01:29 PM
Entering Date on web form mrideout BOOK: Beginning ASP.NET 1.0 6 October 19th, 2004 12:08 PM





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