Date format from 1.1.2009 to 01.01.2009

C

Carl_and_Earl

I want to make a field to change the date from 1.1.2009 to 01.01.2009 on lost
focus.

Thanks!
 
J

John W. Vinson

What is the Format property of the form textbox? -> Short Date
On your Windows desktop select Start... Control Panel... Regional and Language
Settings. What's the Short Date format? ->3/31/2009

That's the problem then.

Change the Format property of the form textbox from Short Date to dd.mm.yyyy
if that's the format you want. Otherwise it inherits the control panel
setting.
 
C

Carl_and_Earl

Thanks John, but it didn't work. I did what you told me, but to change the
field to 01.01.2009 I have to type first 01/01/2009 otherwise it wouldn't let
me to enter the date and I want to input just 1.1.2009 when I tipe to
simplify it.
 
J

John W. Vinson

Thanks John, but it didn't work. I did what you told me, but to change the
field to 01.01.2009 I have to type first 01/01/2009 otherwise it wouldn't let
me to enter the date and I want to input just 1.1.2009 when I tipe to
simplify it.

Hrm. Ok, you're right - it's trying to enter the date as a fractional number!
Wierd.

If your user simply cannot move over one key on the keyboard and type /
instead of . I suspect you'll need to use an unbound textbox and parse the
number into a recognizable date, or change the Control Panel regional short
date format. I've tried a couple of things that didn't work (setting an input
mask frex) and don't have any bright ideas!
 
C

Carl_and_Earl

Thanks for your help anyway, it was much appreciated. Even I still didn't
figured it out, I learned, trying to solve this problem, many other things. :)

Thank you!
 
J

James A. Fortune

Carl_and_Earl said:
I want to make a field to change the date from 1.1.2009 to 01.01.2009 on lost
focus.

Thanks!

Maybe:

Private Sub txtX_LostFocus()
If IsDate(Replace(txtX.Value, ".", "/")) = False Then
MsgBox ("Invalid Date")
Exit Sub
End If
If Not IsNull(txtX.Value) Then txtX.Value _
= Replace(Format(Replace(txtX.Value, ".", "/"), _
"mm/dd/yyyy"), "/", ".")
End Sub

Note: txtX's Format property should be blank.

James A. Fortune
[email protected]
 
J

James A. Fortune

James said:
Maybe:

Private Sub txtX_LostFocus()
If IsDate(Replace(txtX.Value, ".", "/")) = False Then
MsgBox ("Invalid Date")
Exit Sub
End If
If Not IsNull(txtX.Value) Then txtX.Value _
= Replace(Format(Replace(txtX.Value, ".", "/"), _
"mm/dd/yyyy"), "/", ".")
End Sub

Note: txtX's Format property should be blank.

James A. Fortune
[email protected]

This might be better:

Private Sub txtX_LostFocus()
If Not IsNull(txtX.Value) Then
If IsDate(Replace(txtX.Value, ".", "/")) = False Then
MsgBox ("Invalid Date")
Exit Sub
End If
txtX.Value = Replace(Format(Replace(txtX.Value, ".", "/"), _
"mm/dd/yyyy"), "/", ".")
End If
End Sub

James A. Fortune
[email protected]
 
C

Carl_and_Earl

Hah! You got this right! I can't belive it. Works like a charm. Al I had to
do was to replace txtX with the name of my textbox.

Thank you, thank you, thank you!
 
J

John W. Vinson

This might be better:

Private Sub txtX_LostFocus()
If Not IsNull(txtX.Value) Then
If IsDate(Replace(txtX.Value, ".", "/")) = False Then
MsgBox ("Invalid Date")
Exit Sub
End If
txtX.Value = Replace(Format(Replace(txtX.Value, ".", "/"), _
"mm/dd/yyyy"), "/", ".")
End If
End Sub

VERY clever, James... thank you! Filed for future reference (with
attribution). Didn't realize you could tweak the Value property in LostFocus
like that.
 
J

James A. Fortune

John said:
VERY clever, James... thank you! Filed for future reference (with
attribution). Didn't realize you could tweak the Value property in LostFocus
like that.

You're welcome. I'm glad to have been of help.

James A. Fortune
[email protected]

Coming soon to my sig: Entries from Dictionary of Austrailian Slang, 1943
 
Top