We help IT Professionals succeed at work.

Populate Week Number into text box based on date selection

MCaliebe
MCaliebe asked
on
Hi Everyone,

Can anyone tell me how I would code a form to populate a text box based on a date selection in the calandar?  Do I have to pupulate two fields; one for the date picked and a second which is an evaluation of the date to derive the week number (1-52)?

Thanks,

MC
Comment
Watch Question

Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:

Assuming you have a data field [SomeDate] in the recordset that is the record source for your form, and that you have a control (txt_SomeDate) which is bound to that date field, you could set the control source of an unbound control (txt_Week) to:

=datepart("ww", [SomeDate])

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007
Commented:
?datepart("ww", #12-25-2011#)
 53
 53 weeks this year ?

mx
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
Yep, ...if the first day of the weeks is set as Sunday (which coincidentally Xmas happens to fall on this year...)
(If Monday is set as the first day, then its 52 weeks)
untitled.JPG

Author

Commented:
I was not able to determine a way of useing the calendar to pick a date and have the text box result return the week number, however I did make good use of picking the date and pupluating another text box with the "ww" week# using the After Update action.  I decided to use the initial date box for evaluating the day of the week picked as well so this is acceptable.

Thanks,
MC