formatting dates

I

inquirer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top