Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date/Time Picker (2000 SR1a)

    Hi there,

    I'm trying to use the Microsoft Date/Time Picker control on a form and I'm having a couple problems.

    To begin with I need to be able to disable the control depending on whether a particular check box is checked. Disabling the control itself is no problem, but trying to disable its label is getting annoying. A lot of controls (e.g. text boxes, combo boxes, etc.) have their own labels and when you disable the control the label is automatically disabled (i.e. appears as sunken grayed-out letters). But the Date/Time Picker doesn't have its own label. So I thought I'd just add a normal label and disable it. That's when I discovered (or re-discovered) that normal labels can't be disabled. Can someone tell me how I can add a label to my Date/Time Picker that can be disabled?

    Secondly the Date/Time Picker seems to hate being Null. When I advance to a new record the control is Null by default. (I could get around this by adding a default date, but there's no appropriate default value). Then Access gives me this error: "Can't set value to NULL when Checkbox property = FALSE." Can someone help me get around this problem? (Without changing the Checkbox property to True, thereby making the control ugly.)

    Thanks in advance!

    James - jrm@sympatico.ca

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Date/Time Picker (2000 SR1a)

    I can tell you that some of your problems will go away if you turn off the checkbox. It looks like a good way to disable the control, but it has problems of its own. And I don't even try to set the control to Null. I simply use an unbound date time picker so that its value isn't stored anywhere.

    Here's how I work around the problems when I use a date/time picker. I put a textbox over the date/time picker, and I bind that textbox to the field I want to enter the date into. That eliminates both the problem of the label and the problem of having to disable and enable the date time picker--it just gets hidden behind the textbox, which has its own label. Actually, I have a form that has two date/time pickers on it, one to select the beginning date and one for the ending date, but this technique will work just as well with a single date time picker. I hide them when they're not in use, so you only see the textboxes, which can be set to Null without causing errors.

    Here's the OnEnter event for my textbox:<pre>Private Sub txtLWkBeginDt_Enter()

    <font color=448800> 'make sure the End date picker is hidden</font color=448800>
    [oleDTEnd].Visible = False

    <font color=448800> 'display the Begin date picker, and give it
    'a default value</font color=448800>
    [oleDTBegin].Visible = True
    [oleDTBegin].Value = Nz([txtLWkBeginDt], Date)

    <font color=448800> 'set the focus to the date picker</font color=448800>
    [oleDTBegin].SetFocus
    End Sub <font color=448800> 'txtLWkBeginDt_Enter()</font color=448800> </pre>

    Then I use the CloseUp event of the date/time picker like this to set the textbox value:
    <pre>Private Sub oleDTBegin_CloseUp()

    <font color=448800>'check to see if a date has been picked.
    'if there is a changed date in txtLWkBeginDt then ...</font color=448800>
    If ([txtLWkBeginDt] <> [oleDTBegin].Value Or _
    IsNull([txtLWkBeginDt])) And _
    Not IsNull([oleDTBegin].Value) Then

    <font color=448800> 'set the textbox to the changed date</font color=448800>
    [txtLWkBeginDt] = oleDTBegin.Value
    End If <font color=448800> '([txtLWkEndDt] <> [oleDTBegin].Value) And _
    Not IsNull([oleDTBegin].Value)</font color=448800>

    <font color=448800> 'if there is no ending date or if the beginning
    'date was changed, calculate an ending date</font color=448800>
    If (IsNull([txtLWkEndDt]) Or _
    [txtLWkBeginDt].OldValue <> [txtLWkBeginDt].Value) Then

    [txtLWkEndDt] = EndingDate([oleDTBegin].Value, 1, diweek, True)
    End If <font color=448800>'(IsNull([txtLWkEndDt]) Or _
    [txtLWkBeginDt].OldValue <> [txtLWkBeginDt].Value)</font color=448800>
    End Sub <font color=448800> 'oleDTBegin_CloseUp()</font color=448800> </pre>

    You could easily use the DblClick event of the textbox to reset its value to null if you decided not to put in a date.
    Charlotte

  3. #3
    New Lounger
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date/Time Picker (2000 SR1a)

    Thanks! This is great! I wish I had thought of this. It solves all the problems I was having. Now I just have one more little question.

    How do you hide the DatePicker again once the user is done with it? I could put a Visible=False line in the GotFocus event of the next control on the form but, quite frankly, I don't trust the users to go to the next control. They might use the mouse to skip to a completely different control.

    Is there any simple way to hide the DatePicker as soon as the user leaves the control (no matter how they leave it)?

    Thanks again!

    James

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Date/Time Picker (2000 SR1a)

    As long as the textbox is on top, you don't need to hide the date picker, unless you want to hide the dropdown arrow. In that case, you have to use the Enter or GotFocus events of each of the other controls to set the date time picker's visible property to false if necessary.
    Charlotte

Posting Permissions

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