Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2004
    Posts
    33

    Unanswered: Using the Calendar Control

    How do I pass the value of the currently selected date in a calendar object to a text box.?

  2. #2
    Join Date
    Feb 2003
    Location
    Auckland, NZ
    Posts
    150
    Me.TextBox1 = Me.Calender1.Value

    Or if you want to format the date

    Me.TextBox1 = Format(Me.Calender1.Value, "dd/mmm/yyyy")
    JJ Kennedy
    Double J IT Solutions
    www.doublejit.co.nz

    VB 6, VB.NET, ASP.NET, MS SQL Server, MySQL, MS Access

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Remember that you can set the Calendar Controls data source to a column in your datasource. I think if your textbox is set to the same source, then a change in one will automatically propogate to the other.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Mar 2004
    Posts
    33
    After searching the Access 200 Help topics, I found the Calendar Control Events. There is no OnClick event in the properties dialog but you can set one anyway. Here is what I used to have the user click a button and select a date.

    Private Sub MyCalendar_Click()
    Me.Text0 = Me.MyCalendar.Value 'Enters selected date into text box
    Me.Text0.SetFocus 'Move focus away from Calendar Control
    Me.MyCalendar.Visible = False 'Hide the Calendar Object
    Me.btn_SelectDate.Visible = True '
    'Move on to other tasks
    End Sub

    Private Sub btn_SelectDate_Click()
    On Error GoTo Err_btn_SelectDate_Click

    Me.Text0.SetFocus 'Moves focus away from command button or an error will occur
    Me.btn_SelectDate.Visible = False 'Hide the command button just clicked
    Me.MyCalendar.Visible = True 'Display the calendar to select a date

    Exit_btn_SelectDate_Click:
    Exit Sub

    Err_btn_SelectDate_Click:
    MsgBox Err.Description
    Resume Exit_btn_SelectDate_Click

    End Sub

    Now I need to work out how to move the calendar object to a specified X,Y position based on the button clicked. (Maybe a Select Case statement..)

  5. #5
    Join Date
    Mar 2004
    Posts
    2

    Where did you post that last command ?

    I'm new with Access and I was hoping you could help with the Calendar...

    Do you post the code in the Calendar's Event Builder or the Tex Box Event Builder ? Also, the "btn_SelectDate" , is that a source within the Calendar or the Text box where you want the selected date to go. If you could provide any help, I'll really appreciate it ! I hope I can get it working soon. Thanks !

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    ...or try it my way : a separate popup form with the date control on it - i hope the code is sufficiently self documented

    izy
    currently using SS 2008R2

  7. #7
    Join Date
    Mar 2004
    Posts
    2

    Thanks !

    Worked like a charm ! Now how do I get it to work for several values (other textboxes) without having it change only "TextBox1".

  8. #8
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Re: Thanks !

    from izy's original description:

    "the "trick" if it is one, is to pass the object name of the destination textbox to the popup form. (typically i call this from _click in a textbox that is supposed to have a date in it)"

    So, on each of the other text boxes' _OnClick event, you put the following code: (Lets say for a textbox named txtNumber2)

    ' **************
    Dim TargetTextBox As TextBox

    Set TargetTextBox = Me.txtNumber2

    DoCmd.OpenForm "popUserDate"

    Forms!popUserDate.popUserDateSetup txtNumber2, "Put_txtNumber2CaptionHere", Date()
    ' **************

    D.

  9. #9
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    here's my suggestion for a textbox called txtNumber2

    private sub txtNumber2_Click()

    Dim TargetTextBox As TextBox
    Set TargetTextBox = Me.txtNumber2
    DoCmd.OpenForm "popUserDate"
    Forms!popUserDate.popUserDateSetup TargetTextBox, "Put_txtNumber2CaptionHere", txtNumber2

    end sub

    i think it is more "natural" to default to a date currently displayed in the box (if there is one). popUserDate defaults to Now() if the box is not a valid date.

    izy
    currently using SS 2008R2

  10. #10
    Join Date
    Jan 2004
    Posts
    75
    I copied this from somewhere on this forum (my apologies to the originator)... anyway, you can see it can work for endless controls on a form (using arrivefrom and arrive to as examples here). Works like a charm.

    Option Compare Database
    Option Explicit
    Dim Originator As ComboBox

    Private Sub arriveFrom_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
    ' Note which combo box called the calendar
    Set Originator = arriveFrom
    ' Unhide the calendar and give it the focus
    Calendar.Visible = True
    Calendar.SetFocus
    ' Match calendar date to existing date if present or today's date
    If Not IsNull(Originator) Then
    Calendar.Value = Originator.Value
    Else
    Calendar.Value = Date
    End If
    End Sub


    Private Sub arriveTo_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
    ' Note which combo box called the calendar
    Set Originator = arriveTo
    ' Unhide the calendar and give it the focus
    Calendar.Visible = True
    Calendar.SetFocus
    ' Match calendar date to existing date if present or today's date
    If Not IsNull(Originator) Then
    Calendar.Value = Originator.Value
    Else
    Calendar.Value = Date
    End If
    End Sub



    Private Sub Calendar_Click()
    ' Copy chosen date from calendar to originating combo box
    Originator.Value = Calendar.Value
    ' Return the focus to the combo box and hide the calendar and
    Originator.SetFocus
    Calendar.Visible = False
    ' Empty the variable
    Set Originator = Nothing
    End Sub

  11. #11
    Join Date
    Oct 2004
    Posts
    15

    The Easy Way - My Cheat

    I'm a newbie, but I came up with a workaround for posting Beginning Dates and End Dates to a form using the Calendar Control.

    Quite Simply.... on the form that I wanted the dates to populate, I created Calendars (one for Beginning, one for End) and set the Visible properties to false.

    I then set up an event (user clicks button, field has focus, etc.) that changes the respective Calendar to Visible=True. Following that command, set YourField = Calendar.Value

    Just repeat this setup for the second Calendar and field.

    It's a cheap way out... but at least you don't need extensive code, or more than one form to accomplish your goal.

Posting Permissions

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