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

Create your own calendar

Calendars

Create your own calendar

by  gol4  Posted    (Edited  )
How to Create your own Basic Calendar
Create a form that looks like a calendar by Adding:
1 unbound text box .Name it FirstDate Set format to mmmm\ /yyyy
Create 42 unbound text boxes name them D0,D1,D2 >>>>D40, D41 , 6 rows 7 columns
D0,D1,D2,D3,D4,D5,D6,
D7,D8,D9,D10,D11,D12,D13,
D14,D15,D16,D17,D18,D19,D20, You get the Idea!
(Note) donÆt do them 1 at a time create 7 then copy and paste!
1 label placed above the textboxes with caption SUN Mon TUE etc..

paste this code in
////////////////////////////////////////////////////////////////////////////////////////
Start copy below

Private Sub form_open(cancel as integer)
me![FirstDate] = date() æset starting date to current date
call filldates æcall function that fills in calendar
End Sub

Private Function filldates()
Dim curday As Variant, curbox As Integer
curday = DateSerial(Year(Me![firstdate]), Month(Me![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
Me("D" & curbox) = Day(curday)
Me("D" & curbox).Visible = False
If Month(curday) = Month(Me!FirstDate) Then Me("D" & curbox).Visible = True
curday = curday +1 'nextday
Next curbox
End Function

End Copy above
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Run your calendar. Enjoy!
NOTES:
To change month or year just change me![FirstDate] then call filldates() again
Place =filldates() in firstdate afterupdate event
or via a button (my preferred)

Private Sub Command1_Click()
Me!FirstDate = DateAdd("m",1, FirstDate)'increase by 1 month
Call FillDates
End Sub

To determine which date is selected in a text box this works well

dim selday as integer, DateSelected as variant
selday = val(me.activecontrol.value)
dateselected = DateSerial(Year(Me![firstdate]), Month(Me![firstdate]), selday)

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top