Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default formatting dates

Just when I thought I had formatting dates in VBA under control, I
obtained a new PC with Excel 2003 SP2 and a program which used to work
perfectly now gives an error with formatting dates.
Basically I read a date from a listboxbut if the date is blank, I set it
to a default of 01/01/1901

The relevant bits of code are

Dim sDate As Date
Dim stDate As Long

If formInput.ListBox2.Value = "date_entered" Then
sDate = formInput.TextBox3.Value
Else
sDate = "01/01/1901"
End If

stDate = Right(sDate, 4) & Mid(sDate, 4, 2) & Left(sDate, 2)

As I said, this worked ok under a previous version of excel and if sdate
was set to 01/01/1901, stdate correctly became 19010101.

Now even tho sDate is set to "01/01/1901", excel treats it as
"1/01/1901" and consquently stdate is either not evaluated or evaluated
incorrectly.

Can someone please tell me how to overcome this?

I need to finish up with stdate in the form 20051201 (yyyymmdd) after
reading a date from a form )in the format dd/mm/yyyy or dd/mm/yy.

Thanks
Chris
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
Formatting Dates Lynda Excel Discussion (Misc queries) 6 August 19th 09 09:29 AM
Formatting Dates pknivens Excel Discussion (Misc queries) 5 October 3rd 05 09:27 PM
Dates Not Formatting as Dates awacs Excel Worksheet Functions 4 September 13th 05 10:35 PM
Formatting dates rovetrader Excel Worksheet Functions 1 February 14th 05 05:03 PM
Formatting Dates Mike[_58_] Excel Programming 2 November 18th 03 10:34 PM


All times are GMT +1. The time now is 09:40 PM.

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"