How to generate weeknumber and begin of week date in access vba?
Hi guys . I got a table in my db called week. It has the following
feilds on it . Year, weekno and monday. I created a button and a text box in a form.
when i type a year name and press a button i want the the follwing happes:
it check if the year exist in the db. if the year does not exist it goes
and inserts week number from 1 -52 along with start of date and year in to the db. I be happy if some one show me how to do this in access.Thanks
example :
year --- weekno --- monday
2005 1 1/3/2005
2005 2 1/10/2005
2005 3 1/17/2005
. . .
. . .
. . .
. . .
. . .
2005 50 12/26/2005
Re: How to generate weeknumber and begin of week date in access vba?
i think this should work, but test it thoroghly
VB Code:
txtyear = 1997
myyear = "1/1/" & txtyear
da = Weekday(myyear)
mydate = DateAdd("d", 7 - da + 2, myyear)
myweek = Format(mydate, "w", vbMonday)
Debug.Print "Year", "Week No", "Monday"
For myweek = 1 To 52
Debug.Print txtyear, myweek, Format(mydate, "mm/dd/yyyy")
mydate = DateAdd("ww", 1, mydate)
Next
pete