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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default Date for every Thursday 2

Status
Not open for further replies.

Happy2

Programmer
Aug 10, 2001
64
US
Hi everyone,

Can you please help me to set a default for a date field. If I enter a new record any day of the week, I need the default date of THURSDAy for that week. Thanks in advance!
 
You can use the WEEKDAY() function to test which day of the week a date is.

So for a text box control called datControlName:-

Private Sub Form_Load()
datControlName = Date

While Weekday(datControlName) <> 5
datControlName = datControlName + 1
Wend

End Sub

This takes a Friday and adds 6 to get to the NEXT Thursday.
If you want a Friday date to go BACK to the previous Thursday then you'll have to do something else with the logic. ( Select Case perhaps )


QED?

G LS
 
This isn't a very elegant solution, but I think it works.
First, set the default value of your date field to Now().


Then, in the On Current event of your form, enter the following (in the example, the date field is called flddate)

Private Sub Form_Current()
Dim MyDate, MyWeekDay
MyDate = Me!flddate
MyWeekDay = WeekDay(MyDate)
If MyWeekDay = 1 Then
Me!flddate = (Me!flddate + 4)
ElseIf MyWeekDay = 2 Then
Me!flddate = (Me!flddate + 3)
ElseIf MyWeekDay = 3 Then
Me!flddate = (Me!flddate + 2)
ElseIf MyWeekDay = 4 Then
Me!flddate = (Me!flddate + 1)
ElseIf MyWeekDay = 6 Then
Me!flddate = (Me!flddate - 1)
ElseIf MyWeekDay = 7 Then
Me!flddate = (Me!flddate - 2)
Else
Exit Sub
End If
End Sub

HTH
Chris
 
Hi LittleSmudge and krispi,

Thank you so much for your help. I've it work. I really appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top