Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing date in a control (2003 SP2)

    I have a control (formatted as date), that can be changed by entering
    Regards,
    Peter

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Changing date in a control (2003 SP2)

    Why don't you have 2 controls one the specia; char and the other the date. when you exit out of the special char it does the calc on the date field and refreshes the date field.

  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing date in a control (2003 SP2)

    Thanks Pat.
    Could do. But I would need 5 controls; the main control showing the date, another one with a '+', one with a '-', one with a 't' & a label. Controls 2 to 4 would respond to a click to change the main control. No good having only one separate control to type into as it would be very un-intuitive.
    But I still can't see why the current code doesn't work as I want it to.
    Regards,
    Peter

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

    Re: Changing date in a control (2003 SP2)

    I'm going offline for several hours, I'll look at it when I return.

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Changing date in a control (2003 SP2)

    I'm off to bed, but you could have an option box of three check boxes.

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

    Re: Changing date in a control (2003 SP2)

    Try this version. It uses the On Key Press event instead of the On Key Down event. An essential point is that the code "kills" the keystrokes t/T, + and - after handling them. Other keystrokes are passed unchanged.

    Private Sub Contact_Date_KeyPress(KeyAscii As Integer)
    Dim ctl As Control
    Set ctl = Screen.ActiveControl
    Call SetDate(ctl, KeyAscii)
    End Sub

    Function SetDate(ctl As Control, KeyAscii As Integer)
    On Error GoTo Err_SetDate
    Select Case KeyAscii
    Case 84, 116 ' T or t set to today
    ctl = Date
    KeyAscii = 0
    Case 43 ' + adds 1 day
    If IsDate(ctl) Then
    ctl = ctl + 1
    End If
    KeyAscii = 0
    Case 45 ' - subtracts 1 day
    If IsDate(ctl) Then
    ctl = ctl - 1
    End If
    KeyAscii = 0
    End Select
    Exit Function

    Err_SetDate:
    MsgBox Err.Description, vbExclamation
    End Function

  7. #7
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing date in a control (2003 SP2)

    I honestly don't know how you do it.
    It worked a treat. Just like it is supposed to.
    Thanks again (again) Hans. You certainly have phenomenal recall.
    Regards,
    Peter

Posting Permissions

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