Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 21st, 2005, 01:46 PM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to generate weeknumber/begin of week date in

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 the 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
 
Old June 22nd, 2005, 10:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Suppose your year is in the textbox Me.txtYear. Then...

    Dim dtm1stMonday As Date, dtmDate As Date, bytWeekNo As Byte

    'Assume first Monday is January 1.
    dtm1stMonday = DateSerial(Me.txtYear, 1, 1)

    'Correct date if it's NOT Monday.
    dtm1stMonday = DateAdd("d", 2 - Weekday(dtm1stMonday), dtm1stMonday)

    'If correction places you in last Monday of previous year, correct THAT.
    If Year(dtm1stMonday) < Me.txtYear Then
        dtm1stMonday = DateAdd("d", 7, dtm1stMonday)
    End If

    dtmDate = dtm1stMonday
    For bytWeekNo = 1 To 52
        MsgBox Me.txtYear & " " & bytWeekNo & " " & dtmDate, vbInformation, "Mondays in Year"
        dtmDate = DateAdd("d", 7, dtmDate)
    Next bytWeekNo

Change the MsgBox statement in this code to actually assign the bytWeekNo and dtmDate to other textboxes if you wish.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old June 22nd, 2005, 11:13 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by SerranoG
 Suppose your year is in the textbox Me.txtYear. Then...

    Dim dtm1stMonday As Date, dtmDate As Date, bytWeekNo As Byte

    'Assume first Monday is January 1.
    dtm1stMonday = DateSerial(Me.txtYear, 1, 1)

    'Correct date if it's NOT Monday.
    dtm1stMonday = DateAdd("d", 2 - Weekday(dtm1stMonday), dtm1stMonday)

    'If correction places you in last Monday of previous year, correct THAT.
    If Year(dtm1stMonday) < Me.txtYear Then
        dtm1stMonday = DateAdd("d", 7, dtm1stMonday)
    End If

    dtmDate = dtm1stMonday
    For bytWeekNo = 1 To 52
        MsgBox Me.txtYear & " " & bytWeekNo & " " & dtmDate, vbInformation, "Mondays in Year"
        dtmDate = DateAdd("d", 7, dtmDate)
    Next bytWeekNo

Change the MsgBox statement in this code to actually assign the bytWeekNo and dtmDate to other textboxes if you wish.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division

Many thanks to u reply. If i want to insert year,weekno and monday date to week table how shold i do that(just like example below) i be happy if u show me that part.Thanks

year --- weekno --- monday
2005 1 1/3/2005
2005 2 1/10/2005
2005 3 1/17/2005
. . .
. . .
. . .
. . .
. . .
2005 50 12/26/2005





Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining a week from current date... flippyn5 PHP Databases 1 December 2nd, 2005 09:01 PM
How to generate weeknumber and begin of week date method SQL Server 2000 1 June 21st, 2005 01:32 PM
Week number to a date pdistant ASP.NET 1.0 and 1.1 Professional 5 August 17th, 2004 07:44 PM
get the week from the given date Beulah ASP.NET 1.0 and 1.1 Basics 1 September 25th, 2003 11:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.