[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Check to see if a date is formatted correctly

Posted on 2003-03-07
4
Medium Priority
?
140 Views
Last Modified: 2010-05-01
How do I check a users' input for correct formatting:

##/##/####

i.e.

If txtdate.text = Format(txtdate.Text, "##/##/####") Then. . .

0
Comment
Question by:adamkushner
  • 3
4 Comments
 
LVL 3

Expert Comment

by:Diveblue
ID: 8091429
adam,

for your example....


If txtdate.text = Format(txtdate.Text, "mm/dd/yyyy") Then
    'matches
else
    'bad
end if
0
 
LVL 3

Accepted Solution

by:
Diveblue earned 100 total points
ID: 8091439
correction.....

if isdate(txtdate.text ) = false then
  'bad
else
  If txtdate.text = Format(txtdate.Text, "mm/dd/yyyy") Then
     'matches
  else
   'bad
  end if
end if
0
 
LVL 3

Expert Comment

by:Diveblue
ID: 8091483
Another alternative is to use the Microsoft masked edit control instead of the textbox. Add the control to your vb project and set the mask to ##/##/####. That way only numbers can be entered in your desired format. Of course you'll still need to use the isdate function to validate that the user didn't enter bad data (i.e. "12/34/5678")

scott
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8091970
WHy not use a datecontrol.  You will then ensure it is a date without all the code necessary to verify it is a date and there is no confusion as to whether 03/04/2003 is Mar 4 or Apr 3.

mlmcc
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

590 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