Can't get calendar control to work!

PaulSpell

Registered User.
Local time
Today, 10:34
Joined
Apr 19, 2002
Messages
201
I have inserted a calendar control into a form and want to execute some code based on the date selected by the user. Problem is I can't fathom how to do this.

Can anyone help?
 
This is the problem...I haven't really got any yet as I don't know where to put it!

I want to invoke some code which opens another form and passes the date selected when a user clicks on a date. The closest I can get is to use a command button to open the form and pass the date selected (which is ok I guess but not really what I wanted). Is this the only way of using calendar controls?

I think it may be the "On Updated" event that I need, but I can't seem to get it to work.

I have been testing it with:
---------------------------------------------------------
Private Sub Caldr_Updated(Code As Integer)
MsgBox Caldr
End Sub
---------------------------------------------------------

to see whether this will return the date value I select....but it doesn't!

Any suggestions?
 
Last edited:
When I use the Calendar Control this is what I do:

Create a form which holds the Calendar Control ensuring it is modal and taking all the record selecter crap off.

The code on this form is:

Code:
Private mctlDate As Control

Public Property Set DateControl(ByVal ctlDate As Control)

    ' variable declarations
    ' <none>

    Set mctlDate = ctlDate
    
End Property

Public Property Let InitialDate(datD As Date)

    ' variable declarations
    ' <none>

    Me!ctlCalendar.Value = datD

End Property

Private Sub SetAndClose()

    ' variable declarations
    ' <none>

    If mctlDate Is Nothing Then
        MsgBox "The DateControl property has not been set"
    Else
        mctlDate = ctlCalendar.Value
    End If
    
    DoCmd.Close

End Sub


Private Sub ctlCalendar_click()

    SetAndClose
    
End Sub

Private Sub ctlCALENDAR_keyup(KeyCode As Integer, ByVal Shift As Integer)

    Select Case KeyCode
    Case vbKeyReturn        ' carriage return
        SetAndClose
    Case vbKeyEscape          ' escape
        DoCmd.Close
    End Select
    
End Sub


On a typical form I then create a text box (locked and disabled) with the dd-mmm-yyyy format to display the date. I put a command button beside this text box.

The code on the command button is:

Code:
Private Sub cmdStart_Click()

    If IsNull(txtStart) Then
        txtStart = DateValue(Now())
    End If
    Call ShowCalendar(txtStart)
    
End Sub

N.B. I know the reference to the double function is silly, but I don't care.

And finally, I have a module with this code:

Code:
Sub ShowCalendar(ByRef txtDate As TextBox)

    Dim frmCal As Form              ' calendar form
    Dim ctlD As Control             ' date control on this form

    Set ctlD = txtDate
    DoCmd.OpenForm "popCalendar", , , , , acHidden
    Set frmCal = Forms("popCalendar")
    With frmCal
        Set .DateControl = ctlD
            .InitialDate = ctlD.Value
            .Visible = True
    End With

End Sub


This allows me to call the same form (popCalendar) for every time I need to input a date.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom