this will give 1 years worth of date in the future to change it to cover past dates set curday to a previous date
create a list box set its rowsource type to value list
name it combowkend
on the forms oncurrent event
call pickweekend
paste this code in your module
Sub pickweekend()
Dim curday As Variant, curint As Integer, wkendstr As String
curday = Date
Do Until DatePart("w", curday, vbSunday) = 1 'due until Saturday
curday = DateAdd("d", -1, curday) 'set the date to saturday
Loop
For curint = 0 To 53 Step 7 'cover 1 year
curday = DateAdd("d", curint, curday) 'CurDay= next day
wkendstr = wkendstr & DateAdd("d", -1, curday) & ";" & curday & ";"
Next curint
Me.Combowkend.RowSource = wkendstr
End Sub
Sub pickweekend()
Dim curday As Variant, curint As Integer, wkendstr As String
curday = Date
Do Until DatePart("w", curday, vbSunday) = 1 'due until Sunday
curday = DateAdd("d", -1, curday) 'set the date to Sunday
Loop
For curint = 0 To 52 'cover 1 year
Debug.Print curday
wkendstr = wkendstr & DateAdd("ww", curint, curday - 1) & ";" & DateAdd("ww", curint, curday) & ";"
Next curint
Me.Combowkend.RowSource = wkendstr
End Sub
where are you pasting the code? This is intended to work on the forms code. The me.keyword is refering to the form.
make sure you paste it in where the forms on current event appears so it looks like this
Private Sub Form_Current()
call pickweekend()
End Sub
'_________________________________________________________
Sub pickweekend()
Dim curday As Variant, curint As Integer, wkendstr As String
curday = Date
Do Until DatePart("w", curday, vbSunday) = 1 'due until Sunday
curday = DateAdd("d", -1, curday) 'set the date to Sunday
Loop
For curint = 0 To 52 'cover 1 year
wkendstr = wkendstr & DateAdd("ww", curint, curday - 1) & ";" & DateAdd("ww", curint, curday) & ";"
Next curint
Me.Combowkend.RowSource = wkendstr
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.