MsCal AfterUpdate

JamesJoey

Registered User.
Local time
Today, 09:13
Joined
Dec 6, 2010
Messages
642
I've placed the MsCal Calendar Control (acxCal) on a form along with a "Today" button.
I'd like the Today button to be disabled when today is selected on the calendar and enabled when it is not.
I've already the On Click of the button to:

Code:
 Me!acxCal.Value = Date()
This works fine.

But, I'd like the button to be disabled after the calendar selection is today.

I'm assuming I need to put something in the AftewrUpdate of the calendar but I'm not sure how to implement this.

Any help will be appreciated,
James
 
I cannot give u the exact syntax but the general syntax would be:

Code:
AfterUpdate
     Dim xToday As Datetime

     xToday = Now()

     If Date(xToday) = Date(Me!acxCal.Value) Then
         Me.btnToday.Enabled = False
     Else
         Me.btnToday.Enabled = True
     End If

Hope that helps

Note you may have to Cast the Me!acxCal.Value as I am not sure what data type it returns
 
So far nothings working.

I guess I can simply leave the command button enabled.
 
Why do you not share you code it is hard to debug something you cannot see
 
Amending Dennis' code to be more VBA friendly ;)

Code:
[COLOR=Blue] AfterUpdate or Change event ??[/COLOR]

     If Me!acxCal.Value = Date Then
         Me.btnToday.Enabled = False
     Else
         Me.btnToday.Enabled = True
     End If
 
Well I would not call that more friendly. A bit more streamlined but with an implicit conversion something I have found from time to time can cause issues. Still I've been working with visual basic since version 3 and C so I tend to play it more cautiously and make sure I am explicit about conversion as such. Still to each their own.
 
I'm not questioning your code or your use of implicit type conversions. The variable declaration was DateTime which isn't a datatype in VBA, the equivalent is Date. And the type conversion functions used were Date(), but then again the VBA equivalent is CDate() or DateValue(). Also, for a calendar object the return type should be a date type.

I was simply pointing out the obvious because these may have been the reasons why JamesJoey stated "So far nothings working".
 
Check got that and in case it came across wrong was not slamming your code either, just trying to put out a comment about the implicit versus explicit conversion.

As a note I did state that my code was not "exact syntax" which implied the person using it needed to check for the proper syntax. And I did not use implicit conversion I was pointing that your version used implicit type conversion.Thus to rewrite your code using explicit conversion it would look as follows:

Code:
[FONT="Courier New"]     If CDate(Me!acxCal.Value) = Date Then
         Me.btnToday.Enabled = False
     Else
         Me.btnToday.Enabled = True
     End If[/FONT]

Unless I have forgotten something specific to VBA the acxCal.Value would be a string type and not a date type so for explicit conversion to compare apples to apples (which the code needs) it needs to be converted to a date or date would need to be converted to a string. I choose date as a date type is numeric and all code compares numeric easier than it does character.

Again the extra explanation is not for you as I am sure you are already aware of these things. The extra explanation is for anyone else that happens to read this and wonders why.
 
Useful information for those reading this thread DennisOJensen! I'm sure that JamesJoey has learnt something new as well ;)

By the way, MSCAL.ocx returns a Date type - I've just had a Typename() check. It only makes sense for it to return such a type, it being a calendar. However, it still doesn't hurt having a type conversion in there anyway.
 

Users who are viewing this thread

Back
Top Bottom