Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 January 4th, 2007, 05:36 AM
ppenn
Guest
 
Posts: n/a
Default Week Numbers

Hi Happy New Year to everyone
I have added a field into a table called "week numbers" which I want to show the week number through the year, starting at "1" for week beginning 1st January, is there any way this can be done automatically through Access/VBA. I need to be able to look at the date in another field and then update the week number field
Regards
Peter
 
Old January 4th, 2007, 08:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Here is a simple script to demonstrate the syntax of what you want:

dtDate = Date()
iWeek = DatePart("ww", dtDate)
WScript.Echo iWeek

The important part is to take your date, and then use DatePart() on it using ww for work week. Today this script returned 1, since it is the first week of the year.

Does this help?


mmcdonal
 
Old January 4th, 2007, 09:20 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

Hi, Peter. If you have the date stored in another field then you do NOT want to store the week number. Calculated fields should never be stored; rather, they should be recalculated on the fly for your forms and reports. Storing calculated fields inflates your MDB unnecessarily and it creates the probablity of obsolete data if other values used to calculate them change.


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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Week of Year kiwibey ASP.NET 2.0 Professional 0 June 3rd, 2007 11:14 PM
DAY of the week wdepreter Excel VBA 3 February 7th, 2007 06:44 AM
A week of the a year cirudinezidane Javascript 2 July 1st, 2004 09:31 AM
My week with threads freezotic BOOK: Beginning Java 2 0 April 16th, 2004 04:27 PM





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