An easy calendar

Gkirkup

Registered User.
Local time
Today, 03:13
Joined
Mar 6, 2007
Messages
628
I needed to add a working calendar to an application. First I drew a calendar grid, seven days wide and six weeks deep (you need six weeks on the calendar for some months.) I put a control into every date on the grid, Date1 through Date42. Looks good so far!
Then I used a combo box to load STARTMONTH on my form, with the first day of the month I want to see. Then I used this code to load the dates for any month:

Code:
[FONT=Arial]Private Sub Form_Current()[/FONT]
[FONT=Arial][/FONT]
[FONT=Arial]Dim daynum As Long[/FONT]
[FONT=Arial]Dim startmonth As Date[/FONT]
[FONT=Arial][/FONT]
[FONT=Arial]startmonth = Me.MONTHSTART[/FONT]
[FONT=Arial][/FONT]
[FONT=Arial]daynum = Weekday(Me.MONTHSTART)[/FONT]
[FONT=Arial][/FONT]
[FONT=Arial]' Assign dates to cells[/FONT]
[FONT=Arial]Me.Date1 = startmonth + (1 - daynum)[/FONT]
[FONT=Arial]Me.Date2 = startmonth + (2 - daynum)[/FONT]
[FONT=Arial]Me.Date3 = startmonth + (3 - daynum)[/FONT]
[FONT=Arial]Me.Date4 = startmonth + (4 - daynum)[/FONT]
[FONT=Arial]Me.Date5 = startmonth + (5 - daynum)[/FONT]
[FONT=Arial]Me.Date6 = startmonth + (6 - daynum)[/FONT]
[FONT=Arial]Me.Date7 = startmonth + (7 - daynum)[/FONT]
[FONT=Arial]Me.Date8 = startmonth + (8 - daynum)[/FONT]
[FONT=Arial]Me.Date9 = startmonth + (9 - daynum)[/FONT]
[FONT=Arial]Me.Date10 = startmonth + (10 - daynum)[/FONT]
[FONT=Arial]Me.Date11 = startmonth + (11 - daynum)[/FONT]
[FONT=Arial]Me.Date12 = startmonth + (12 - daynum)[/FONT]
[FONT=Arial]Me.Date13 = startmonth + (13 - daynum)[/FONT]
[FONT=Arial]Me.Date14 = startmonth + (14 - daynum)[/FONT]
[FONT=Arial]Me.Date15 = startmonth + (15 - daynum)[/FONT]
[FONT=Arial]Me.Date16 = startmonth + (16 - daynum)[/FONT]
[FONT=Arial]Me.Date17 = startmonth + (17 - daynum)[/FONT]
[FONT=Arial]Me.date18 = startmonth + (18 - daynum)[/FONT]
[FONT=Arial]Me.Date19 = startmonth + (19 - daynum)[/FONT]
[FONT=Arial]Me.Date20 = startmonth + (20 - daynum)[/FONT]
[FONT=Arial]Me.Date21 = startmonth + (21 - daynum)[/FONT]
[FONT=Arial]Me.Date22 = startmonth + (22 - daynum)[/FONT]
[FONT=Arial]Me.Date23 = startmonth + (23 - daynum)[/FONT]
[FONT=Arial]Me.Date24 = startmonth + (24 - daynum)[/FONT]
[FONT=Arial]Me.Date25 = startmonth + (25 - daynum)[/FONT]
[FONT=Arial]Me.Date26 = startmonth + (26 - daynum)[/FONT]
[FONT=Arial]Me.Date27 = startmonth + (27 - daynum)[/FONT]
[FONT=Arial]Me.Date28 = startmonth + (28 - daynum)[/FONT]
[FONT=Arial]Me.Date29 = startmonth + (29 - daynum)[/FONT]
[FONT=Arial]Me.Date30 = startmonth + (30 - daynum)[/FONT]
[FONT=Arial]Me.Date31 = startmonth + (31 - daynum)[/FONT]
[FONT=Arial]Me.Date32 = startmonth + (32 - daynum)[/FONT]
[FONT=Arial]Me.Date33 = startmonth + (33 - daynum)[/FONT]
[FONT=Arial]Me.Date34 = startmonth + (34 - daynum)[/FONT]
[FONT=Arial]Me.Date35 = startmonth + (35 - daynum)[/FONT]
[FONT=Arial]Me.Date36 = startmonth + (36 - daynum)[/FONT]
[FONT=Arial]Me.Date37 = startmonth + (37 - daynum)[/FONT]
[FONT=Arial]Me.Date38 = startmonth + (38 - daynum)[/FONT]
[FONT=Arial]Me.Date39 = startmonth + (39 - daynum)[/FONT]
[FONT=Arial]Me.Date40 = startmonth + (40 - daynum)[/FONT]
[FONT=Arial]Me.Date41 = startmonth + (41 - daynum)[/FONT]
[FONT=Arial]Me.Date42 = startmonth + (42 - daynum)[/FONT]
[FONT=Arial][/FONT]
[FONT=Arial][/FONT]
[FONT=Arial][/FONT] 
[FONT=Arial]End Sub[/FONT]

That's all there is to it! To change the month just change STARTMONTH to a new start month date and do a requery. To be fancy, you can withhold the dates that are not in the current month displayed. I made them grey and left them in place.

Robert
 
Is there a question here? If not, this is in the wrong forum. Also, that is essential how CyberCow's example works. That example only displays dates in the current month, and allows you to put entries in each day's box.
 
Yes, I did ask a question about how to program a simple calendar. I never got a reply, so this is my answer.

Robert
 
@Gkitkup

If you asked a question and never got an answer, you should have posted this as an answer to your question rather than a new thread. Saves confusion and keeps things tidy. Also, if its cybercows code, then you should state that instead of acting that its your own. Credit where credits due

@ speakers
I don't believe CyberCow is on the forum unless he has another persona. If he is here, he's very inactive. Try mentioning where he is known and how he is known. You know, the 'other' forum where rules have rules and everyone is so far up gords hole, you can't get a fieler gauge between them. The place where humour and laughter is strictly forbidden at every level and everyone takes themselves far tooooo seiously ;)

Btw, not aimed at everyone at ua, just the handful lol :)


Sent from my OMNIA7 using Board Express
 

Users who are viewing this thread

Back
Top Bottom