DTPicker: Problem getting user input to a text field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sid666
    New Member
    • Mar 2007
    • 4

    #1

    DTPicker: Problem getting user input to a text field

    Hi, everyone

    I'm building an Access DB system using VBA. I have a ActiveX DTPicker so the user can select a date. This date is put in another textbox that is bound to a table. I do this because if I make the DTPicker bound to the table then the date keeps changing to the current date (or the date that was last selected) when I scroll through the records on the form. I just made the DTPicker so small that only the dropdown arrow is visible and put it right next to the bound textbox. The event that I use in DTPicker to write the value to the textbox is "On Lost Focus" like this:
    Code:
    Private Sub DTPicker9_LostFocus()
        Dim pos As Integer
        pos = InStr(DTPicker9.Value, " ")
        Me.txtbox = Left(DTPicker9.Value, pos)
    End Sub
    This works fine but I want the textbox to show the new date as soon as the user selects it, not when the DTPicker looses focus. I don't know how to do it because DTPicker only has these events; On updated, On Enter, On Exit, On Got Focus and On Lost Focus. It seems to me I will need somthing like On Change event.

    I've really been pulling my hair over this so hopfully someone has a solution to this problem.
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. What happens if you use the onupdated event?

    Comment

    • vijaydiwakar
      Contributor
      • Feb 2007
      • 579

      #3
      Originally posted by Sid666
      Hi, everyone

      I'm building an Access DB system using VBA. I have a ActiveX DTPicker so the user can select a date. This date is put in another textbox that is bound to a table. I do this because if I make the DTPicker bound to the table then the date keeps changing to the current date (or the date that was last selected) when I scroll through the records on the form. I just made the DTPicker so small that only the dropdown arrow is visible and put it right next to the bound textbox. The event that I use in DTPicker to write the value to the textbox is "On Lost Focus" like this:
      Code:
      Private Sub DTPicker9_LostFocus()
          Dim pos As Integer
          pos = InStr(DTPicker9.Value, " ")
          Me.txtbox = Left(DTPicker9.Value, pos)
      End Sub
      This works fine but I want the textbox to show the new date as soon as the user selects it, not when the DTPicker looses focus. I don't know how to do it because DTPicker only has these events; On updated, On Enter, On Exit, On Got Focus and On Lost Focus. It seems to me I will need somthing like On Change event.

      I've really been pulling my hair over this so hopfully someone has a solution to this problem.
      I've not get thy problem well but i think u may try textbox's gotfocus event as
      Code:
       
      Private Sub Text1_GotFocus()
      Text1 = dtp.Value
      End Sub

      Comment

      • Sid666
        New Member
        • Mar 2007
        • 4

        #4
        Originally posted by willakawill
        Hi. What happens if you use the onupdated event?
        Hi. Yes, I had tried the On updated event but it didn't work.

        Comment

        • Sid666
          New Member
          • Mar 2007
          • 4

          #5
          Originally posted by vijaydiwakar
          I've not get thy problem well but i think u may try textbox's gotfocus event as
          Code:
           
          Private Sub Text1_GotFocus()
          Text1 = dtp.Value
          End Sub
          I'm not better off using the OnGotFocus event of the textbox because the DTPicker gets the focus first when the user selects the date. Then the textbox gets the focus and the date appears in the textbox (because I use the OnLostFocus event of the DTPicker). I will try to explain my problem better: I want the date to appear in the textbox the same time the user selects (clicks on) the date in the DTPicker so the user can see instantly the date in the textbox not when the DTPicker looses focus.
          I'm just concerned about that if the user-click has no response (i.e. no date appears in the textbox) that will be confusing to the user.

          Hope you get my point... any other ideas?

          Comment

          • vijaydiwakar
            Contributor
            • Feb 2007
            • 579

            #6
            Originally posted by Sid666
            I'm not better off using the OnGotFocus event of the textbox because the DTPicker gets the focus first when the user selects the date. Then the textbox gets the focus and the date appears in the textbox (because I use the OnLostFocus event of the DTPicker). I will try to explain my problem better: I want the date to appear in the textbox the same time the user selects (clicks on) the date in the DTPicker so the user can see instantly the date in the textbox not when the DTPicker looses focus.
            I'm just concerned about that if the user-click has no response (i.e. no date appears in the textbox) that will be confusing to the user.

            Hope you get my point... any other ideas?
            I don't no whether i get it or not if yes then try this code
            Code:
             
            Private Sub DTPicker1_Change()
            Text1.Text = DTPicker1.Value
            End Sub
            
            
            Private Sub DTPicker1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
            Text1.Text = DTPicker1.Value
            End Sub

            Comment

            • Sid666
              New Member
              • Mar 2007
              • 4

              #7
              Originally posted by vijaydiwakar
              I don't no whether i get it or not if yes then try this code
              Code:
               
              Private Sub DTPicker1_Change()
              Text1.Text = DTPicker1.Value
              End Sub
              
              
              Private Sub DTPicker1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
              Text1.Text = DTPicker1.Value
              End Sub
              Like I said in the first post, DTPicker only has the following events: On Updated, On Enter, On Exit, On Got Focus and On Lost Focus. So I don't know how I can use the subs you suggest (Change and MouseUp). Should I implement them myself, and if so what would be the triggering event?

              Comment

              • vijaydiwakar
                Contributor
                • Feb 2007
                • 579

                #8
                Originally posted by Sid666
                Like I said in the first post, DTPicker only has the following events: On Updated, On Enter, On Exit, On Got Focus and On Lost Focus. So I don't know how I can use the subs you suggest (Change and MouseUp). Should I implement them myself, and if so what would be the triggering event?
                No dear the code i've given is tested by me. I had droped ctrl from mswindows comman ctrl

                Comment

                • microwave
                  New Member
                  • Jun 2007
                  • 1

                  #9
                  Originally posted by Sid666
                  Like I said in the first post, DTPicker only has the following events: On Updated, On Enter, On Exit, On Got Focus and On Lost Focus. So I don't know how I can use the subs you suggest (Change and MouseUp). Should I implement them myself, and if so what would be the triggering event?
                  You may have solved this already since March, but after struggling with the same problem, I noticed that on switching to the VBA code editor for the form conaining my Date Time Picker control, and selecting my DTPicker0 control in the top left-hand dropdown box,
                  in the right-hand drop-down box there are many more events listed than are shown in the MS Access Property Box; One of them is "Change"... .

                  That created a subroutine

                  Private Sub DTPicker0_Chang e()
                  unbound_ctrl_Da te = DTPicker0.Value
                  End Sub

                  Which updates my unbound control whenever I select a date.
                  Which I think is what you wanted to do.

                  Comment

                  Working...