?
Solved

Check to see if a date is formatted correctly

Posted on 2003-03-07
4
Medium Priority
?
137 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
[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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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

771 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