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

weekend in dropdown

Status
Not open for further replies.

rry2k

Programmer
Jun 28, 2001
678
US
Hi,

Is there a way to fill a dropdown with weekend dates? I would also like it to be dynamic if possible so I don't have to change it every year.

Thanks..Russ
 
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
 
I apologize for above posting
pasted wrong code

use this code

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
 
No apoligy neccessary. I'll try this but when I tried the old it said invalid use of me keyword.

I'll try the latest and see what happens.

Thanks..Russ
 
It still didn't like the me keyword. should I use the form name like form1! ?
 
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

 
Got it. One more quick question. How do I make it list just Saturday or Sunday. Currently I have a 12/8 and 12/9.

Thanks alot for the help..Russ
 
the majority of the action happens on this line

wkendstr = wkendstr & DateAdd("ww", curint, curday - 1) & ";" & DateAdd("ww", curint, curday) & ";"

to just show saturday drop the last part so the line reads

wkendstr = wkendstr & DateAdd("ww", curint, curday - 1) & ";"

to just show sunday
wkendstr = wkendstr & DateAdd("ww", curint, curday) & ";"
 
Thanks I appreciate your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top