Calendar Option for Date field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bluemoon9
    New Member
    • Oct 2008
    • 56

    Calendar Option for Date field

    hello everyone!
    I would like to add a calenda option onto the form next to the Date field, so that user can just select the date from the calendar instead of typing the date, can someone help?

    thanks!
    bluemoon
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32656

    #2
    When using the Toolbox toolbar (Form design) there is an option at the end called "More Controls". In there you should find a standard one called "Calendar Control n.n".

    Comment

    • bluemoon9
      New Member
      • Oct 2008
      • 56

      #3
      thanks! but then I would like to hide the calenda until user click on a little button next to the Date field. I was thinking of add a command button next to the Date field, when user click on the command button, calenda open as a dialog form. Does it work that way? is there any other better way, since I have about 10 date fields, I would have to make 10 pop up dialog forms.

      thanks!
      bluemoon

      Comment

      • bluemoon9
        New Member
        • Oct 2008
        • 56

        #4
        Hi,
        What I did was I put the calenda next to the Date field and set Visible=No, then I put a command button next to the date field, when user click on the command button, I made the calenda visible=true, but then I don't know how to make the calenda visibile=false when user is done with date selection.

        thanks!

        bluemoon

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          How about setting up an AfterUpdate event procedure for the control that is being set by the Calendar control. When that runs it can set the Calendar control back to invisible.

          You could even make the showing of it triggered by entering the other control (On Enter) instead of having to add loads of Command Buttons.

          Sound like an idea?

          Comment

          • bluemoon9
            New Member
            • Oct 2008
            • 56

            #6
            NeoPa,
            You mean to add the code "me.calenda.vis ible=false" onto the AfterUpdate of the DateField? I did that but it did't really work.
            In the calenda Event Property, it only has 5 events: On Updated, On enter, On Exit, On Got Focus and On Lost Focus, I've tried them all and nothing works. Please help.

            thanks!
            Bluemoon

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32656

              #7
              Originally posted by bluemoon9
              NeoPa,
              You mean to add the code "me.calenda.vis ible=false" onto the AfterUpdate of the DateField? I did that but it did't really work.
              I do mean that. In what way do you mean it didn't work.

              Comment

              • bluemoon9
                New Member
                • Oct 2008
                • 56

                #8
                Originally posted by NeoPa
                I do mean that. In what way do you mean it didn't work.
                well, once I selected the date from the calenda, I hit enter key in the keyboard to select the date, the selected date appear in the DateField box, but then the calendar still visible.

                thanks alot for your help.
                bluemoon

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32656

                  #9
                  Can you post all the code you have for the controls involved?

                  Comment

                  • bluemoon9
                    New Member
                    • Oct 2008
                    • 56

                    #10
                    Originally posted by NeoPa
                    Can you post all the code you have for the controls involved?
                    Yup, here is the code.
                    My form has a field call txtDate. I place a small cmdCal next to the txtDate field and the calendar next to the cmdCal button, but calendar is set to Visible=No (in the property). When user click on the cmdCal, Calendar is set to visible=true, then user choose a date, then hit enter, the selected date appears in the txtDate box, then I want the calendar to be invisible.

                    here is my code
                    Code:
                    Private Sub cmdCal_Click()
                    Me.Calendar.Visible = True
                    End Sub
                    
                    Private Sub txtDate_AfterUpdate()
                    Me.Calendar.Visible = False
                    End Sub
                    thanks alot!
                    bluemoon.

                    if you have any other idea, please advise. basicly, I just need to have a pull-up calendar for the date fields, that's all.

                    Comment

                    • itchysf
                      New Member
                      • Aug 2008
                      • 31

                      #11
                      You could try this code, the txtbox is changed to a combobox when it is clicked on the calendar becomes visiable and the date can be selected which goes into the combobox and calendar becomes invisable. I have called the combobox (startdate), you can change that to what ever suits you.



                      Code:
                      Private Sub StartDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
                      
                      ' Unhide the calendar and give it the focus
                          Calendar4.Visible = True
                         Calendar4.SetFocus
                      ' Match calendar date to existing date if present or today's date
                          If Not IsNull(StartDate) Then
                             Calendar4.Value = Date
                          Else
                             Calendar4.Value = StartDate.Value
                          End If
                          
                      End Sub
                      
                      Private Sub Calendar4_Click()
                      ' Copy chosen date from calendar to originating combo box
                         StartDate.Value = Calendar4.Value
                      ' Return the focus to the combo box and hide the calendar
                         StartDate.SetFocus
                         Calendar4.Visible = False
                      
                      End Sub
                      Hope this helps

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32656

                        #12
                        Try :
                        Code:
                        Private Sub cmdCal_Click()
                            Me.Calendar.Visible = True
                        End Sub
                        
                        Private Sub Calendar_AfterUpdate()
                            Me.Calendar.Visible = False
                        End Sub
                        Hopefully that will work. I'm not sure why your code didn't but I can't test it from here.

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32656

                          #13
                          Also, look at Itchy's code. Although i wouldn't use the events he's used, there is some code in there that could add to the friendliness of your app. Worth nicking I would say ;)

                          Comment

                          • bluemoon9
                            New Member
                            • Oct 2008
                            • 56

                            #14
                            Thank you!

                            bluemoon

                            Comment

                            • bluemoon9
                              New Member
                              • Oct 2008
                              • 56

                              #15
                              Originally posted by itchysf
                              You could try this code, the txtbox is changed to a combobox when it is clicked on the calendar becomes visiable and the date can be selected which goes into the combobox and calendar becomes invisable. I have called the combobox (startdate), you can change that to what ever suits you.



                              Code:
                              Private Sub StartDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
                              
                              ' Unhide the calendar and give it the focus
                                  Calendar4.Visible = True
                                 Calendar4.SetFocus
                              ' Match calendar date to existing date if present or today's date
                                  If Not IsNull(StartDate) Then
                                     Calendar4.Value = Date
                                  Else
                                     Calendar4.Value = StartDate.Value
                                  End If
                                  
                              End Sub
                              
                              Private Sub Calendar4_Click()
                              ' Copy chosen date from calendar to originating combo box
                                 StartDate.Value = Calendar4.Value
                              ' Return the focus to the combo box and hide the calendar
                                 StartDate.SetFocus
                                 Calendar4.Visible = False
                              
                              End Sub
                              Hope this helps
                              Hi,
                              I used your code and it worked just fine. But there is only one problem left. When I click select TODAY DATE from the calenda, it gave me the date of 12/30/1899 in my Date box. And this happend only the first round. For example, if I select TODAY DATE on the calendar, it gave me the date of 12/30/1899, then I reselect, it gave me the correct date of (10/15/2008). Any idea why? I have no clue why it happended that way.

                              thanks!
                              bluemoon

                              Comment

                              Working...