Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default User Form Text Date Format

I am setting up a User Form to enter data. Most of the Combo Boxes work very
well but the 2 date boxes are challenging me! I had thought I could format
the User Form through Properties but that appears not the case. I have tried
a couple of suggestions I have seen in the forum:
Private Sub TextBox4_Change()
TextBox4.Value = Format(TextBox4.Value, "d mmm yy")
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox4.Value = Format(TextBox4.Value, "d mmm yy")
End Sub

The first example pre-fills the User Form box with 31 Dec 99 no matter what
key I touch.
The second example behaves as folows:
I enter 2 Mar 10 and get 2 Mar 10 in the Sheet but get 3 Feb 10 in the User
Form.
I enter 2 Dec 09 and get 2 Dec 09 in the Sheet but get 3 Feb 10 in the User
Form.
I enter 02/09/09 and get 9 Feb 09 in the Sheet but correctly 2 Sep 09 in the
User Form.

I wonder if anyone can shed some light on where I may be going wrong. Many
thanks.

Glenn
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default User Form Text Date Format

Hi Glenn

Use 'CDate' to convert the data to a true date before formatting it:

Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox4.Value = Format(CDate(TextBox4.Value), "d mmm yy")
End Sub

Hopes this helps.
....
Per

On 2 Mar., 21:43, Glenn wrote:
I am setting up a User Form to enter data. *Most of the Combo Boxes work very
well but the 2 date boxes are challenging me! I had thought I could format
the User Form through Properties but that appears not the case. *I have tried
a couple of suggestions I have seen in the forum:
Private Sub TextBox4_Change()
TextBox4.Value = Format(TextBox4.Value, "d mmm yy")
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox4.Value = Format(TextBox4.Value, "d mmm yy")
End Sub

The first example pre-fills the User Form box with 31 Dec 99 no matter what
key I touch.
The second example behaves as folows:
I enter 2 Mar 10 and get 2 Mar 10 in the Sheet but get 3 Feb 10 in the User
Form.
I enter 2 Dec 09 and get 2 Dec 09 in the Sheet but get 3 Feb 10 in the User
Form.
I enter 02/09/09 and get 9 Feb 09 in the Sheet but correctly 2 Sep 09 in the
User Form.

I wonder if anyone can shed some light on where I may be going wrong. *Many
thanks.

Glenn


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default User Form Text Date Format

Many thanks Per, but unfortunately there is no change to my problem.

Glenn

"Per Jessen" wrote:

Hi Glenn

Use 'CDate' to convert the data to a true date before formatting it:

Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox4.Value = Format(CDate(TextBox4.Value), "d mmm yy")
End Sub

Hopes this helps.
....
Per

On 2 Mar., 21:43, Glenn wrote:
I am setting up a User Form to enter data. Most of the Combo Boxes work very
well but the 2 date boxes are challenging me! I had thought I could format
the User Form through Properties but that appears not the case. I have tried
a couple of suggestions I have seen in the forum:
Private Sub TextBox4_Change()
TextBox4.Value = Format(TextBox4.Value, "d mmm yy")
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox4.Value = Format(TextBox4.Value, "d mmm yy")
End Sub

The first example pre-fills the User Form box with 31 Dec 99 no matter what
key I touch.
The second example behaves as folows:
I enter 2 Mar 10 and get 2 Mar 10 in the Sheet but get 3 Feb 10 in the User
Form.
I enter 2 Dec 09 and get 2 Dec 09 in the Sheet but get 3 Feb 10 in the User
Form.
I enter 02/09/09 and get 9 Feb 09 in the Sheet but correctly 2 Sep 09 in the
User Form.

I wonder if anyone can shed some light on where I may be going wrong. Many
thanks.

Glenn


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default User Form Text Date Format

If you want to avoid any confusion when inputting dates in VBA or from a
Userform, (like the day being taken for the month and the month for the
day), always enter the date with the YYYY/MM/DD format.
That format is well interpreted by the Sheet and by VBA.

You may also use the computer's "Short Date" format. Even if it varies from
one computer to another, it is also always correctly interpreted.

TextBox1.Value = Format(TextBox1.Value, "Short date")

Range("A1").value = Format(TextBox1.Value, "Short date")


Mishell


"Glenn" a écrit dans le message de news:
...
I am setting up a User Form to enter data. Most of the Combo Boxes work
very
well but the 2 date boxes are challenging me! I had thought I could format
the User Form through Properties but that appears not the case. I have
tried
a couple of suggestions I have seen in the forum:
Private Sub TextBox4_Change()
TextBox4.Value = Format(TextBox4.Value, "d mmm yy")
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox4.Value = Format(TextBox4.Value, "d mmm yy")
End Sub

The first example pre-fills the User Form box with 31 Dec 99 no matter
what
key I touch.
The second example behaves as folows:
I enter 2 Mar 10 and get 2 Mar 10 in the Sheet but get 3 Feb 10 in the
User
Form.
I enter 2 Dec 09 and get 2 Dec 09 in the Sheet but get 3 Feb 10 in the
User
Form.
I enter 02/09/09 and get 9 Feb 09 in the Sheet but correctly 2 Sep 09 in
the
User Form.

I wonder if anyone can shed some light on where I may be going wrong.
Many
thanks.

Glenn



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
International date format and user form James Price at Premier Excel Programming 0 April 6th 09 08:21 AM
Date format changes when inputed from user form Lynz Excel Discussion (Misc queries) 16 December 13th 08 11:27 PM
visual basic user form date format dd/mm/yy not mm/dd/yy DarrenO Excel Discussion (Misc queries) 1 March 28th 07 01:56 AM
date format in user form TUNGANA KURMA RAJU Excel Programming 1 August 7th 06 06:17 AM
how to format a date/validate for a text box entry on a user form Tom Ogilvy Excel Programming 3 June 1st 05 05:06 PM


All times are GMT +1. The time now is 09:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"