Calculate to Next Sunday

I need to put a label in my access application that simply shows me the date for the following Sunday.  For example if today is Friday 3rd then it would show that the next date of the next sunday is 5th.  But when we get to Monday 6th I need that label to automatically show the following sunday which would be the 12th and so fourth.  Basically I have a rent charging application and the charges are calculated weekly on a sunday, and I need the label to show the next charge date

Any help would be greatly appreciated.
LVL 3
ihotdeskAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
datepart("w", now(), vbSunday) returns the day of the week, sunday being 1
hence, use
dateadd("d", 8 - datepart("w", now(), vbSunday), now()) to get the next sunday

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ihotdeskAuthor Commented:
sorry to be a pain but I am new at Access and have basically inherited this application do I have to set the first line the datepart as a variable in the form before I can use the second line to display the info I need in a text box
p912sCommented:
You don't need that first part, angelIII was just showing you that using that function to return the day of the week for Sunday that Sunday = 1.

In the On Current or On Open or where ever it makes sense add this code. This assumes your date field is named txtDate.

   Me.txtDate = DateAdd("d", 8 - DatePart("w", Now(), [vbSunday]), Now())
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

ihotdeskAuthor Commented:
thanks guys thats exactly what I was looking for :)
p912sCommented:
You're welcome...
bobHackerCommented:

Hi,

This is a simple function I did one to get Saturday as a weekending date

Public Function getWeekEndingDate() As Date
Dim dayOfWeek As Integer
Dim dteWeekEndingDate As Date

dayOfWeek = Weekday(Date)

'test
'dayOfWeek = 7

Select Case dayOfWeek
       Case 1
            dteWeekEndingDate = DateAdd("d", 6, Date)
       Case 2
            dteWeekEndingDate = DateAdd("d", 5, Date)
       Case 3
            dteWeekEndingDate = DateAdd("d", 4, Date)
       Case 4
            dteWeekEndingDate = DateAdd("d", 3, Date)
       Case 5
            dteWeekEndingDate = DateAdd("d", 2, Date)
       Case 6
            dteWeekEndingDate = DateAdd("d", 1, Date)
       Case 7
            dteWeekEndingDate = Date
       Case Else
            'error message... or
            'dteWeekEndingDate = Date  
End Select

'return
getWeekEndingDate = dteWeekEndingDate

End Function
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.