Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Oct 2003
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    UpDown.2 Control (VBA XP)

    I am using a MSComCtl2.UpDown.2 control to move forward or backward in a date field. I have it working where each up/down click is equal to one day movement. I am trying to have it continue to change the date when holding the button down. Any help would be appreciated. Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: UpDown.2 Control (VBA XP)

    The UpDown control should do that automatically. How do you increase/decrease the date?

  3. #3
    Star Lounger
    Join Date
    Oct 2003
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UpDown.2 Control (VBA XP)

    On Down Click: Me.Date = Me.Date - 1

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: UpDown.2 Control (VBA XP)

    I would use the On Change event instead of the On Up Click and On Down Click events:

    Private Sub UpDown1_Change()
    Static lngOldVal As Long
    If Me.UpDown1 > lngOldVal Then
    Me.Date = Me.Date + 1
    Else
    Me.Date = Me.Date - 1
    End If
    lngOldVal = UpDown1
    End Sub

    where UpDown1 is the name of the UpDown control.

  5. #5
    Star Lounger
    Join Date
    Oct 2003
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UpDown.2 Control (VBA XP)

    Thanks...that worked great. One more idea...how could I modify it so it just increments the month or year? Me.Date is a Short Date formatted field.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: UpDown.2 Control (VBA XP)

    Instead of Me.Date = Me.Date - 1, use Me.Date = DateAdd("m", -1, Me.Date) for months, or Me.Date = DateAdd("yyyy", -1, Me.Date) for years. Similar for + instead of -.

  7. #7
    Star Lounger
    Join Date
    Oct 2003
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UpDown.2 Control (VBA XP)

    Thanks again...your unbelievably quick response is very much appreciated.

Posting Permissions

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