Help with Dates

E

Eric

I have a section of code that no matter what I do it is
formatting the dates back in the 1890's. This is not when
I need the dates set to please take a look at this section
of code that was sent to me by another more experienced
user and see if you all have any ideas.

Private Sub Form_Load()
Dim dtStart As Date
Dim iDowStart As Integer
Dim dtKt As Date
Dim iBox As Integer


dtStart = July - 2003
iDowStart = Weekday(dtStart)

For dtKt = dtStart To DateAdd("m", 1, dtStart) - 1
iBox = (Day(dtKt) + iDowStart - 2) Mod 35
Me("dt" & iBox) = dtKt
If iBox < 6 Or iBox > 27 Then
Me("sub" & iBox).Visible = True

End If
Next
Me.Caption = Format(dtStart, "mmmm yyyy")

End Sub

Thanks for your help.
 
J

John Vinson

dtStart = July - 2003

A Date/Time field is stored as a double float number, a count of days
and fractions of a day since midnight, December 30, 1899. This
expression will subtract 2003 days from the value of the variable July
(perhaps equal to 7), giving a date in the 1890's as you see.

Try

dtStart = #7/1/2003#

to set the date to July 1; or perhaps better to have it always start
at the first of the current month,

dtStart = DateSerial(Year(Date), Month(Date), 1)
 

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

Top