PC Review


Reply
Thread Tools Rate Thread

Calendar Control - Years

 
 
=?Utf-8?B?UGhpbGlwIEogU21pdGg=?=
Guest
Posts: n/a
 
      24th Apr 2007
Hi I've used the tutorial at www.fontstuff.com/vba/vbatut07.htm to set up a
calendar for date selection in a cell.

I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
Ogilvy to pick up the Friday of the week for any date selected.

ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
vbSaturday), "dd-mmm-yy")

I'd like to know if it is possible limit the start and end years which can
be selected from the Calendar, say 2003 - 2012.

Can anyone help please?

Regards
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      24th Apr 2007
hi Philip

You can check the value(date) when you click on the control (click event) and when it is before 2003 jump to
the first date you allow and if it is after the last date jump to your last date.

If you need help post back

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Philip J Smith" <(E-Mail Removed)> wrote in message
news:3F1BDBF0-99AD-47BB-88EE-(E-Mail Removed)...
> Hi I've used the tutorial at www.fontstuff.com/vba/vbatut07.htm to set up a
> calendar for date selection in a cell.
>
> I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
> Ogilvy to pick up the Friday of the week for any date selected.
>
> ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
> vbSaturday), "dd-mmm-yy")
>
> I'd like to know if it is possible limit the start and end years which can
> be selected from the Calendar, say 2003 - 2012.
>
> Can anyone help please?
>
> Regards


 
Reply With Quote
 
=?Utf-8?B?UGhpbGlwIEogU21pdGg=?=
Guest
Posts: n/a
 
      24th Apr 2007
Hi Ron.

Can you give me the syntax for the first of these so that I can replicate it
for the Second please?

Regards

Phil

"Ron de Bruin" wrote:

> hi Philip
>
> You can check the value(date) when you click on the control (click event) and when it is before 2003 jump to
> the first date you allow and if it is after the last date jump to your last date.
>
> If you need help post back
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Philip J Smith" <(E-Mail Removed)> wrote in message
> news:3F1BDBF0-99AD-47BB-88EE-(E-Mail Removed)...
> > Hi I've used the tutorial at www.fontstuff.com/vba/vbatut07.htm to set up a
> > calendar for date selection in a cell.
> >
> > I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
> > Ogilvy to pick up the Friday of the week for any date selected.
> >
> > ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
> > vbSaturday), "dd-mmm-yy")
> >
> > I'd like to know if it is possible limit the start and end years which can
> > be selected from the Calendar, say 2003 - 2012.
> >
> > Can anyone help please?
> >
> > Regards

>
>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      24th Apr 2007
In the click event you can use this two events

If Calendar1.Value < 37622 Then Calendar1.Value = 37622
If Calendar1.Value > 41274 Then Calendar1.Value = 41274


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Philip J Smith" <(E-Mail Removed)> wrote in message
news:989EAA71-3551-4CC0-B677-(E-Mail Removed)...
> Hi Ron.
>
> Can you give me the syntax for the first of these so that I can replicate it
> for the Second please?
>
> Regards
>
> Phil
>
> "Ron de Bruin" wrote:
>
>> hi Philip
>>
>> You can check the value(date) when you click on the control (click event) and when it is before 2003 jump to
>> the first date you allow and if it is after the last date jump to your last date.
>>
>> If you need help post back
>>
>> --
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>>
>> "Philip J Smith" <(E-Mail Removed)> wrote in message
>> news:3F1BDBF0-99AD-47BB-88EE-(E-Mail Removed)...
>> > Hi I've used the tutorial at www.fontstuff.com/vba/vbatut07.htm to set up a
>> > calendar for date selection in a cell.
>> >
>> > I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
>> > Ogilvy to pick up the Friday of the week for any date selected.
>> >
>> > ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
>> > vbSaturday), "dd-mmm-yy")
>> >
>> > I'd like to know if it is possible limit the start and end years which can
>> > be selected from the Calendar, say 2003 - 2012.
>> >
>> > Can anyone help please?
>> >
>> > Regards

>>
>>


 
Reply With Quote
 
stevebriz
Guest
Posts: n/a
 
      25th Apr 2007


Youl could do something like this

Private Sub Calendar1_Click()
If Year(Calendar1.Value) < 2003 Or Year(Calendar1.Value) > 2007 Then
MsgBox "Please select Date between the Years 2003 and 2007"
End Sub

 
Reply With Quote
 
David G
Guest
Posts: n/a
 
      25th Apr 2007
On Apr 24, 9:22 am, Philip J Smith
<PhilipJSm...@discussions.microsoft.com> wrote:
> Hi I've used the tutorial atwww.fontstuff.com/vba/vbatut07.htmto set up a
> calendar for date selection in a cell.
>
> I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
> Ogilvy to pick up the Friday of the week for any date selected.
>
> ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
> vbSaturday), "dd-mmm-yy")
>
> I'd like to know if it is possible limit the start and end years which can
> be selected from the Calendar, say 2003 - 2012.
>
> Can anyone help please?
>
> Regards


This way is not particularly simple, but:
1. Remove the regular calendar month/year combo-boxes by setting "Show
Date Selectors" to "False" for the Calendar.
2. Create two new combo-boxes called MonthBox and YearBox.
3. Add the following code to the UserForm (assumed the calendar object
is called Cal):

Private Sub YearBox_Change()
Dim new_date As Date, eom_date As Date
new_date = DateSerial(YearBox, DateTime.month(Cal),
DateTime.Day(Cal))
eom_date = EoMonth(DateSerial(YearBox, DateTime.month(Cal), 1), 0)

If new_date < eom_date Then
Cal = new_date
Else
Cal = eom_date
End If
End Sub

Private Sub MonthBox_Change()
Dim new_date As Date, eom_date As Date
new_date = DateSerial(DateTime.year(Cal), MonthBox.ListIndex + 1,
DateTime.Day(Cal))
eom_date = EoMonth(DateSerial(DateTime.year(Cal),
MonthBox.ListIndex + 1, 1), 0)

If new_date < eom_date Then
Cal = new_date
Else
Cal = eom_date
End If
End Sub

Private Sub UserForm_Initialize()
' Set calendar date to now, if you want
Cal = Now()

Dim year As Integer, month As Integer
With YearBox
For year = 2003 To 2012
.AddItem year
Next year
YearBox.Text = DateTime.year(Cal)
End With

With MonthBox
For month = 1 To 12
MonthBox.AddItem MonthName(month)
Next month
MonthBox = MonthName(DateTime.month(Cal))
End With
End Sub


Make sure you enable the Analysis ToolPak - VBA addin. And I wouldn't
recommend typing into the new combo-boxes, but I don't remember if you
can lock them but still allow users to select from them.

Cheers,
David

 
Reply With Quote
 
Guest
Posts: n/a
 
      27th Apr 2007
This worked for me.

Private Sub Calendar1_NewYear()
Me.Calendar1.ValueIsNull = False
If Year(Me.Calendar1) >= 2012 Then
MsgBox "NO!"
Me.Calendar1.PreviousYear
End If
If Year(Me.Calendar1) <= 2003Then
MsgBox "NO!"
Me.Calendar1.NextYear
End If
End Sub

"David G" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Apr 24, 9:22 am, Philip J Smith
> <PhilipJSm...@discussions.microsoft.com> wrote:
> > Hi I've used the tutorial atwww.fontstuff.com/vba/vbatut07.htmto set up

a
> > calendar for date selection in a cell.
> >
> > I've used an earlier posting (12/5/2006 6:28 AM Calendar Control) by Tom
> > Ogilvy to pick up the Friday of the week for any date selected.
> >
> > ActiveCell.Value = Format(Calendar1.Value - Weekday(Calendar1.Value,
> > vbSaturday), "dd-mmm-yy")
> >
> > I'd like to know if it is possible limit the start and end years which

can
> > be selected from the Calendar, say 2003 - 2012.
> >
> > Can anyone help please?
> >
> > Regards

>
> This way is not particularly simple, but:
> 1. Remove the regular calendar month/year combo-boxes by setting "Show
> Date Selectors" to "False" for the Calendar.
> 2. Create two new combo-boxes called MonthBox and YearBox.
> 3. Add the following code to the UserForm (assumed the calendar object
> is called Cal):
>
> Private Sub YearBox_Change()
> Dim new_date As Date, eom_date As Date
> new_date = DateSerial(YearBox, DateTime.month(Cal),
> DateTime.Day(Cal))
> eom_date = EoMonth(DateSerial(YearBox, DateTime.month(Cal), 1), 0)
>
> If new_date < eom_date Then
> Cal = new_date
> Else
> Cal = eom_date
> End If
> End Sub
>
> Private Sub MonthBox_Change()
> Dim new_date As Date, eom_date As Date
> new_date = DateSerial(DateTime.year(Cal), MonthBox.ListIndex + 1,
> DateTime.Day(Cal))
> eom_date = EoMonth(DateSerial(DateTime.year(Cal),
> MonthBox.ListIndex + 1, 1), 0)
>
> If new_date < eom_date Then
> Cal = new_date
> Else
> Cal = eom_date
> End If
> End Sub
>
> Private Sub UserForm_Initialize()
> ' Set calendar date to now, if you want
> Cal = Now()
>
> Dim year As Integer, month As Integer
> With YearBox
> For year = 2003 To 2012
> .AddItem year
> Next year
> YearBox.Text = DateTime.year(Cal)
> End With
>
> With MonthBox
> For month = 1 To 12
> MonthBox.AddItem MonthName(month)
> Next month
> MonthBox = MonthName(DateTime.month(Cal))
> End With
> End Sub
>
>
> Make sure you enable the Analysis ToolPak - VBA addin. And I wouldn't
> recommend typing into the new combo-boxes, but I don't remember if you
> can lock them but still allow users to select from them.
>
> Cheers,
> David
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to look up previous years calendar =?Utf-8?B?UmljaGFyZA==?= Microsoft Outlook Calendar 1 30th Mar 2006 08:27 PM
How do I add an extra day to a calendar every four years =?Utf-8?B?cGFkZHltYWNr?= Microsoft Excel New Users 3 31st May 2005 10:00 AM
excel calendar years =?Utf-8?B?d2hvd2F0d2Vyd3lob3c=?= Microsoft Excel Misc 1 16th May 2005 12:28 PM
excel calendar years =?Utf-8?B?d2hvd2F0d2Vyd3lob3c=?= Microsoft Excel Programming 1 16th May 2005 12:26 PM
excel calendar years =?Utf-8?B?d2hvd2F0d2Vyd3lob3c=?= Microsoft Excel Misc 0 16th May 2005 12:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:00 PM.