Results 1 to 4 of 4
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    calendar control - no change (Word XP)

    I can find no mention of this in VBA forum, so here goes.

    I'm using a Calendar Control. It fires up with a preset date ( frmDate.cal1 = Date)

    If the user changes the month, but does NOT click on a day, and then chooses OK, the returned value is the preset value.

    There seems to be no way to obtain the result "The user decided not to go ahead with this anyway" if the user changes the month, but not the day, and chooses OK.

    I can trap Cancel and set a .Tag to "".
    I can't test for a change in frmDate.cal1 = Date, because the user might browse around and then decide to stick with today's date anyway.

    Is my logic off key yet again?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: calendar control - no change (Word XP)

    It seems that you want it both ways.... return a date when the user, in his head, wants it that way, but return a blank date (if that is possible) when the user, in his head, feels differently. Classic VB cannot read minds; I don't know whether that has been added to .Net. I think you will have to capture the user's intentions on the underlying form rather than the calendar control.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: calendar control - no change (Word XP)

    To expand on Jefferson's reply: add a text box to your form, and populate it in the On Click event of the calendar control. Just changing the month or year doesn't raise the On Click event, so if the user only changes the month or year, the text box will remain blank. As soon as the user clicks on a date, the text box will be filled. Apart from that, I would provide a Cancel button, so that the user can cancel even if he/she already selected a date.

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: calendar control - no change (Word XP)

    > It seems that you want it both ways....

    Give me time, give me time .....(grin!).

    I had not read far enough. This morning i discovered two events on the calendar control:
    cal1_NewMonth() and cal1_NewYear().
    Those do the trick.
    When the use clicks for a new month or a new year I clear my internal status (cmdOK.Tag="") to show that al bets are off.
    only when the user selects a day in the newly chosn year/month do I set my internal status ON (with Me.cmdOK.Tag = Format(dt, "YYYYMMDD") )
    <pre>Dim dt As Date
    Private Const strcOKCaption As String = "OK"
    Private Sub cal1_Click()
    dt = Me.cal1
    Me.cmdOK.Caption = strcOKCaption & vbCrLf & Format(dt, strcFormatHumanStringDateDeletionDefault)
    End Sub
    Private Sub cal1_NewMonth()
    Call ClearOK
    End Sub
    Private Sub cal1_NewYear()
    Call ClearOK
    End Sub
    Private Sub cmdCancel_Click()
    Me.hide
    End Sub
    Private Sub cmdok_Click()
    Me.cmdOK.Tag = Format(dt, "YYYYMMDD")
    Me.hide
    End Sub
    Private Sub UserForm_Initialize()
    dt = Me.cal1
    Call ClearOK
    End Sub
    Private Function ClearOK()
    Me.cmdOK.Tag = ""
    Me.cmdOK.Caption = strcOKCaption
    End Function</pre>


    Thanks to both you and Hans for prodding me in the right direction.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •