after update:  get date from week number

Posted on 2013-06-01
Last Modified: 2013-06-01
Can anyone help me out with this:

I want to calculate the date field on a form with after update the week field. so I fill in week 23 and it has to calculate the date (friday) in june.
Question by:mvdwal
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 61

Accepted Solution

mbizup earned 500 total points
ID: 39212996
Give this a try in the AfterUpdate event of your weeknumber field:

Me.txtFridayDate =  (Me.txtWeeknum  * 7 + DateSerial(Year(Date), 1, 1) - Weekday(DateSerial(Year(Date), 1, 1))) - 1

Open in new window

- txtWeekNum is the name of the textbox where the week number is entered
- txtFridayDate is the textbox where you want the results displayed

Author Comment

ID: 39213000
Great! It is working! Thanks a lot. Saves a lot of time. I have the date part working. And I was already guesing the date for a week number.... :-)
LVL 61

Expert Comment

ID: 39213003
You may also want to provide handling for nulls, 0, negative and invalid entries... here are some ideas, but you can customize it as needed:

      ' if nothing is entered, just exit without doing anything
       if Trim(Me.txtWeeknum & "")  = ""  then exit sub
      if isNumeric( Me.txtWeeknum)  = false then
              msgBox "Please enter a valid weeknumber"
               exit sub
      end if

       if Me.txtWeekNumber <= 0 Or Me.txtWeekNumber > 53 then
             msgbox "WeekNumber must be between 1 and 53"
             exit sub
       end if

        Me.txtFridayDate =  (Me.txtWeeknum  * 7 + DateSerial(Year(Date), 1, 1) - Weekday(DateSerial(Year(Date), 1, 1))) - 1

Open in new window


Author Comment

ID: 39213020
Yes you may be right! Thanks a lot!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question