Kd wrote:
I am currently using a form with Weekdays
Mon
Tues
Wed
Thur
Fri
This is generated by a table that the days are being entered manually
I would like to create a form that the days updated themselves by 7
days each time a new record is opened.
Any and all thought are appreciated
Kd
There is a weekday function. By Default, Sunday is 1, Saturday is 7.
You need to supply a date to it tho. Let's say we enter in debug window
? Weekday(Date())
Since today is Oct 18th, 2005...a Tuesday, the number is 3. So if we enter
? date() + 8-weekday(Date())
we alway go to the next Sunday
From here, we can display either a 3 char day name or the full day name
? format(Date(),"ddd")
Tue
? format(Date(),"dddd")
Tuesday
Now you want to create a record with the days. It might be better to
fill in the field with the date instead of day name because you can
always format it to display the day but...
Dim rst As DAO.Recordset
Dim intFor As Integer
Dim datStart As Date
datStart = date() + 8-weekday(Date())
set rst = Currentdb.Openrecordset("TableToAdd7DaysName",dbop endynaset)
For intFor = 0 to 6
rst.AddNew
'add the date and later use format
rst!DateFieldName = datStart + intFor
'or add the 3 day format
rst!DayNameString = Format(datStart + intFor,"ddd")
'or add the full day format
rst!DayNameString = Format(datStart + intFor,"dddd")
rst.update
Next
rst.close
set rst = Nothing
You can cut this code out and paste in a module and run it as an example
of how it works.
Sub junk()
Dim intFor As Integer
Dim datStart As Date
datStart = Date + 8 - WeekDay(Date)
For intFor = 0 To 6
'add the date and later use format
MsgBox datStart + intFor & vbNewLine & _
Format(datStart + intFor, "ddd") & vbNewLine & _
Format(datStart + intFor, "dddd")
Next
End Sub