#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 318
Default Date format in VBA

Hello I'm creating a user form in VBA. the Label is "Date received" and
this is what I have.
Me.txtDate = Format(Date, "mmm-dd-yy")
problem is that this shows the current date. What I want is for the person
to enter the date but no mattter how the date is entered to be formatted as
mmm-dd-yy thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Date format in VBA

Hi,

It's a big ask to be able to allow people to enter a date in 'any' format
and expect Excel to recognise that but with a recognisable date in the text
box this gives the result you want.

Private Sub txtdate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtdate = vbNullString Then Exit Sub
If IsDate(txtdate) Then
txtdate = Format(txtdate, "mmm-dd-yyyy")
Else
MsgBox "Non valid date"
Cancel = True
End If
End Sub

Mike

"Wanna Learn" wrote:

Hello I'm creating a user form in VBA. the Label is "Date received" and
this is what I have.
Me.txtDate = Format(Date, "mmm-dd-yy")
problem is that this shows the current date. What I want is for the person
to enter the date but no mattter how the date is entered to be formatted as
mmm-dd-yy thanks

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Date format in VBA

You may want to consider using a calendar control. It'll remove any ambiguity
from what the user enters.

Did the user mean Jan 2, 2003 or Mar 1, 2002 when he or she typed 01/02/03 in
the text box.

See Ron de Bruin's site:
http://www.rondebruin.nl/calendar.htm

Wanna Learn wrote:

Hello I'm creating a user form in VBA. the Label is "Date received" and
this is what I have.
Me.txtDate = Format(Date, "mmm-dd-yy")
problem is that this shows the current date. What I want is for the person
to enter the date but no mattter how the date is entered to be formatted as
mmm-dd-yy thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 318
Default Date format in VBA

Thanks
This is perfect but
Can I use this calendar in a user form? Data is being entered using a user
form I created. Thanks Dave
"Dave Peterson" wrote:

You may want to consider using a calendar control. It'll remove any ambiguity
from what the user enters.

Did the user mean Jan 2, 2003 or Mar 1, 2002 when he or she typed 01/02/03 in
the text box.

See Ron de Bruin's site:
http://www.rondebruin.nl/calendar.htm

Wanna Learn wrote:

Hello I'm creating a user form in VBA. the Label is "Date received" and
this is what I have.
Me.txtDate = Format(Date, "mmm-dd-yy")
problem is that this shows the current date. What I want is for the person
to enter the date but no mattter how the date is entered to be formatted as
mmm-dd-yy thanks


--

Dave Peterson

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
convert serial date format to normal date format Flagworld Excel Discussion (Misc queries) 3 September 23rd 08 01:32 PM
Convert date from text format to date format Anita Excel Discussion (Misc queries) 3 June 4th 07 11:57 AM
Convert date + time text format to date format Paul Ho Excel Worksheet Functions 2 May 22nd 07 05:47 PM
Can I change a date with no format (20051111) to date format? Rose New Users to Excel 2 November 11th 05 09:03 PM
Excel 2000 date format cannot be set to Australian date format Brian Jones Excel Discussion (Misc queries) 1 March 30th 05 06:03 AM


All times are GMT +1. The time now is 12:02 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"