Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a label be the date of the following Sunday

Status
Not open for further replies.

jabarden

Technical User
Jun 16, 2003
19
US
Is there any way to make a label have the date of the Sunday that is coming up without manually typing it in?
Thanks for the help.
 
=IIf(Weekday(Date())=1,Date(),Date()+(8-Weekday(Date())))

That will give you the next Sunday (the iif statement is to keep Sundays from jumping a week ahead). Put this in a text box...you can't do it in a label.

Hope that helps.

Kevin
 
Here is something I just tried. Put this in a module and set the caption of the label equal to this function in the On Current event of your form.

Public Function NextSunday()
Dim i As Integer
Dim targetDate As Date

Do Until i = 7
targetDate = DateAdd("d", i, Date)

If Weekday(targetDate) = 1 Then
NextSunday = targetDate
Exit Do
End If

i = i + 1

Loop

End Function

Hope it is what you are looking for.



ProDev, MS Access Applications
Visit me at ==> Contact me at ==>lonniejohnson@prodev.us

May God bless you beyond your imagination!!!
 
In the Format event for the Report header you would put
Me.lblName.Caption = Date()- Weekday(Date()) + 8
This assumes two things. One is you don't have a field named Date in your Report because if you do Access is likely to make Date() into a field (at least that's what it did in my text report)so if you do you may need to use Now() and Format() out the time portion. Two, this assumes Sunday is the first day of week. If you have any other setting there you will have to test for that. But assuming you don't have either situation, the expression should work as posted. Change lblName to your label name.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top