find the date of Friday

N

Newbie

Hi,

I want to be able to set the default date of a date/time picker to the
Friday date for either the current week or the next week dependant on when
the report is run.
i.e if I open the form on monday/tuesday or Wed 7th, 8th, 9th June I want
the date to be the Fri of the same week i.e 11th June.
If I open the form on Thursday or Friday 10th/11th June I want the date to
be the Friday of the following week i.e. 18th June.

How would I achieve this?

Thanks
 
N

Nikos Yannacopoulos

Try the following piece of code in the form's On Open event:

Dim wday As Integer, fday As Date

wday = Weekday(Date(), vbSaturday)
If wday >= 6 Then wday = wday - 7
fday = Date() - wday + 7

Me.ActivexCtl1 = fday

Just change ActivexCtl1 to the actual name of your Date/Time Picker control.

HTH,
Nikos
 
N

Newbie

Brilliant! works a treat

Thanks for your help

Nikos Yannacopoulos said:
Try the following piece of code in the form's On Open event:

Dim wday As Integer, fday As Date

wday = Weekday(Date(), vbSaturday)
If wday >= 6 Then wday = wday - 7
fday = Date() - wday + 7

Me.ActivexCtl1 = fday

Just change ActivexCtl1 to the actual name of your Date/Time Picker control.

HTH,
Nikos
 
C

Chris Large

Not sure about the dtPicker control, but for a text box
can set the Default value property to:-

Date()+9-Weekday(Date(),5)

which gives you the date you wanted.

hth

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top