Too Many Dates

D

DS

I have a calendar form that essentially works.
I have 42 textoxes that fill with values 1 -31 depending on the month
but the problem is that after it gets to the End of the Month I get an
additional 6 days. I need to fill the textboxes "D" up to the last day
of the month. How can I correct this?
Thanks DS


Me.FirstDate = DateAdd("m", -1, FirstDate) 'decrease by 1 month
Dim curday As Variant, curbox As Integer
curday = DateSerial(Year(Forms!frmCalendarBlack![FirstDate]),
Month(Forms!frmCalendarBlack![FirstDate]), 1) 'first day of month
curday = DateAdd("d", 1 - Weekday(curday), curday) 'back to sunday
For curbox = 0 To 41 'need to loop thru 42 textboxes
Forms!frmCalendarBlack("D" & curbox) = Day(curday)
Forms!frmCalendarBlack("D" & curbox).Visible = False
If Month(curday) = Month(Forms!frmCalendarBlack!FirstDate) Then
Forms!frmCalendarBlack("D" & curbox).Visible = True
curday = curday + 1 'nextday
Next curbox
 
M

Marshall Barton

DS said:
I have a calendar form that essentially works.
I have 42 textoxes that fill with values 1 -31 depending on the month
but the problem is that after it gets to the End of the Month I get an
additional 6 days. I need to fill the textboxes "D" up to the last day
of the month. How can I correct this?
Thanks DS


Me.FirstDate = DateAdd("m", -1, FirstDate) 'decrease by 1 month
Dim curday As Variant, curbox As Integer
curday = DateSerial(Year(Forms!frmCalendarBlack![FirstDate]),
Month(Forms!frmCalendarBlack![FirstDate]), 1) 'first day of month
curday = DateAdd("d", 1 - Weekday(curday), curday) 'back to sunday
For curbox = 0 To 41 'need to loop thru 42 textboxes
Forms!frmCalendarBlack("D" & curbox) = Day(curday)
Forms!frmCalendarBlack("D" & curbox).Visible = False
If Month(curday) = Month(Forms!frmCalendarBlack!FirstDate) Then
Forms!frmCalendarBlack("D" & curbox).Visible = True
curday = curday + 1 'nextday
Next curbox


There are too many FirstDate things in there for me to be
sure what's going on. I can't see any thing obviously wrong
with your code, but this does what I think you want:

Dim curday As Date, curbox As Integer
curday = DateSerial(Year(FirstDate),Month(FirstDate), 1)
curday = DateAdd("d", 1 - Weekday(curday), curday)
For curbox = 0 To 41
Me("D" & curbox) = Day(curday)
Me("D" & curbox).Visible = _
(Month(curday) = Month(FirstDate)
curday = curday + 1
Next curbox
 

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

Similar Threads


Top