Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Calendar Control

Discussion in 'Information Technology' started by Larry G., Jul 28, 2006.

  1. Larry G.

    Larry G.
    Expand Collapse
    Guest

    I want to use a calendar control to allow the user to select a start date and
    end date for a range on a report, I have a text box that is named Start_Date
    and another named End_Date, I have added a calendar control for each text box
    Calendar8 and Calendar9. Each calendar is invisible until a user clicks a
    button to bring them up.

    My question is how do I get the textboxes to display the date that the user
    selects from the calendar control? I tried this:

    Private Sub Calendar8_Updated(Code As Integer)
    Me.Start_Date.Value = Me.Calendar8.Value

    Me.Calendar8.Visible = False

    End Sub

    But is does nothing. Any help is appreciated more than you know!
    --
    Never give up, the answer IS out there, it just takes a while to find it
    sometimes!
     
  2. Loading...


  3. xRoachx

    xRoachx
    Expand Collapse
    Guest

    Hi Larry -- See this link:

    http://www.fontstuff.com/access/acctut09.htm


    "Larry G." wrote:

    > I want to use a calendar control to allow the user to select a start date and
    > end date for a range on a report, I have a text box that is named Start_Date
    > and another named End_Date, I have added a calendar control for each text box
    > Calendar8 and Calendar9. Each calendar is invisible until a user clicks a
    > button to bring them up.
    >
    > My question is how do I get the textboxes to display the date that the user
    > selects from the calendar control? I tried this:
    >
    > Private Sub Calendar8_Updated(Code As Integer)
    > Me.Start_Date.Value = Me.Calendar8.Value
    >
    > Me.Calendar8.Visible = False
    >
    > End Sub
    >
    > But is does nothing. Any help is appreciated more than you know!
    > --
    > Never give up, the answer IS out there, it just takes a while to find it
    > sometimes!
     
  4. Ken Sheridan

    Ken Sheridan
    Expand Collapse
    Guest

    Rather than using the calendar control's Updated event procedure try using
    its Click event procedure. Although not exposed in the control's properties
    sheet it does exist and can be called in the form's module.

    I use a separate form to hold the calendar control. The form can be called
    from the DblClick event procedure of any control on a form with:

    Dim strControl As String

    strControl = Me.ActiveControl.Name

    ' attempt to open calendar form
    If Not OpenCalendar(Me.Name, strControl) Then
    MsgBox "Unable to open calendar", vbExclamation, "Error"
    End If

    This calls the following function in a standard module:

    Public Function OpenCalendar(strCurrentForm As String, strCurrentControl As
    String) As Boolean

    On Error GoTo ErrHandler

    OpenCalendar = True

    ' open calendar form in dialog mode, passing names of form
    ' and control to it as OpenArgs property
    DoCmd.OpenForm "frmCalendar", WindowMode:=acDialog, _
    OpenArgs:=strCurrentForm & "/" & strCurrentControl

    ExitHere:
    Exit Function

    ErrHandler:
    OpenCalendar = False
    Resume ExitHere

    End Function

    The module of the form holding the calendar control is:

    Option Compare Database
    Option Explicit

    Private Sub Form_Close()

    Dim intSlashPos As Integer
    Dim strForm As String, strControl As String

    ' parse form's OpenArgs property to get calling
    ' form and control's names and set control's value
    ' to date selected in calendar control
    If Len(Me.OpenArgs) > 0 Then
    intSlashPos = InStr(1, Me.OpenArgs, "/")
    strForm = Left$(Me.OpenArgs, intSlashPos - 1)
    strControl = Mid$(Me.OpenArgs, intSlashPos + 1)
    Forms(strForm).Controls(strControl) = ocxcalendar
    End If

    End Sub


    Private Sub ocxcalendar_Click()

    DoCmd.Close

    End Sub

    Private Sub ocxcalendar_GotFocus()

    ' set calendar control to current date
    Me.ocxcalendar.Today

    End Sub

    Ken Sheridan
    Stafford, England

    "Larry G." wrote:

    > I want to use a calendar control to allow the user to select a start date and
    > end date for a range on a report, I have a text box that is named Start_Date
    > and another named End_Date, I have added a calendar control for each text box
    > Calendar8 and Calendar9. Each calendar is invisible until a user clicks a
    > button to bring them up.
    >
    > My question is how do I get the textboxes to display the date that the user
    > selects from the calendar control? I tried this:
    >
    > Private Sub Calendar8_Updated(Code As Integer)
    > Me.Start_Date.Value = Me.Calendar8.Value
    >
    > Me.Calendar8.Visible = False
    >
    > End Sub
    >
    > But is does nothing. Any help is appreciated more than you know!
    > --
    > Never give up, the answer IS out there, it just takes a while to find it
    > sometimes!
     

Share This Page