Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date validation in form textbox

Status
Not open for further replies.

Boomerang

Programmer
Mar 30, 2001
766
0
0
NL
I have a textbox in a form in a word template.
the user has to fill in the date in this textbox.

The regional settings is a European country. The date format is "d mmmm yyyyy"

In the code the date is checked with IsDate(vlxContol.Text)

For all clearness":
European date = d-m-y
US date = m-d-y

When I fill in a date 13-10-2002 I got a "TRUE" and the date is filled in as 13 october 2002.
That's a good situation for me.

But when I fill in a date 10-13-2002 I got also a "TRUE" but the date is also filled as 13 october 2002.

How can I change my code that the date 10-13-2002 is not accepted as a valid date?

Hope someone can help me,
Erik <-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
go to the setting -> control panel -> regional opptions-> date -> short date format :
chage the format there as you want like : dd/mm/yyyy
enjoy
 
That's not what I mean, amsh7

The regional settings is already set to a European country. And it doesn't matter the format is European dd/mm/yy or d/mmmm/yyyy.

What matters is that in spite of the regional settings is set to a european country, the date filled in the textbox as a US format (m/d/y) is accepted by the IsDate function as I described.

Who can help me?
PLEASE !!!!!

Erik
<-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
You'll have to ignore the isdate function and write your own. I did something similar in VB a while back:

'this splits the caption of the selected date down into it's components
'and uses this to recreate a date in the standard format

Dim n As Integer: Dim sep() As String: Dim monthname As String: Dim dayname As String
For n = 0 To 3
If OptDate(n).Value = True Then sep = Split(OptDate(n).Caption, &quot;/&quot;)
Next n
kylua = sep(0) + sep(1) + sep(2)
Select Case sep(1)
Case 1
monthname = &quot;January&quot;
Case 2
monthname = &quot;February&quot;
Case 3
monthname = &quot;March&quot;
Case 4
monthname = &quot;April&quot;
Case 5
monthname = &quot;May&quot;
Case 6
monthname = &quot;June&quot;
Case 7
monthname = &quot;July&quot;
Case 8
monthname = &quot;August&quot;
Case 9
monthname = &quot;September&quot;
Case 10
monthname = &quot;October&quot;
Case 11
monthname = &quot;November&quot;
Case 12
monthname = &quot;December&quot;
End Select
thedate = sep(0) + &quot; &quot; + monthname + &quot; &quot; + sep(2)
If Weekday(thedate) = 4 Then dayname = &quot;Wed&quot;
If Weekday(thedate) = 7 Then dayname = &quot;Sat&quot;
Select Case sep(0)
Case &quot;1&quot;, &quot;21&quot;, &quot;31&quot;
frmMain.lblTitle.Caption = &quot;Results for &quot; + dayname + &quot; &quot; + sep(0) + _
&quot;st &quot; + monthname
Case &quot;2&quot;, &quot;22&quot;
frmMain.lblTitle.Caption = &quot;Results for &quot; + dayname + &quot; &quot; + sep(0) + _
&quot;nd &quot; + monthname
Case &quot;3&quot;, &quot;23&quot;
frmMain.lblTitle.Caption = &quot;Results for &quot; + dayname + &quot; &quot; + sep(0) + _
&quot;rd of &quot; + monthname
Case Else
frmMain.lblTitle.Caption = &quot;Results for &quot; + dayname + &quot; &quot; + sep(0) + _
&quot;th &quot; + monthname
End Select

There should be an easier way, but I haven't found it. The date function is just too flexible.
 
Sorry, just remembered. The above example was written in VB6, VBA doesn't support split so you'll have to prog that manually.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top