Results 1 to 2 of 2

Thread: How to generate weeknumber and begin of week date in access vba?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow 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
    Last edited by tony007; Jun 21st, 2005 at 02:03 PM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to generate weeknumber and begin of week date in access vba?

    i think this should work, but test it thoroghly

    VB Code:
    1. txtyear = 1997
    2. myyear = "1/1/" & txtyear
    3. da = Weekday(myyear)
    4. mydate = DateAdd("d", 7 - da + 2, myyear)
    5. myweek = Format(mydate, "w", vbMonday)
    6. Debug.Print "Year", "Week No", "Monday"
    7. For myweek = 1 To 52
    8.     Debug.Print txtyear, myweek, Format(mydate, "mm/dd/yyyy")
    9.     mydate = DateAdd("ww", 1, mydate)
    10. Next

    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width