Solved

after update:  get date from week number

Posted on 2013-06-01
4
623 Views
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.
0
Comment
Question by:mvdwal
  • 2
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
Comment Utility
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
0
 

Author Comment

by:mvdwal
Comment Utility
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.... :-)
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
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

0
 

Author Comment

by:mvdwal
Comment Utility
Yes you may be right! Thanks a lot!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now