Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    DTPicker (Word 2002)

    I'm using the Date and Time Picker Control in a VBA Application. I can't fine much Help on it, and I'm wondering what the purpose of the CheckBox property is. I see that it adds a checkbox to the control, which can be checked at run-time by the user, or is checked automatically when the calendar is displayed by the user.

    I could avoid setting the CheckBox property value to True if I could figure out how to set the value of the control to today's date. For this control, which I have named dtStart (there is also a dtEnd should a range of dates be needed), my code reads:

    dtStart.Value = Format(Date, "m/d/yyyy")

    The "short date" format of this control uses the m/d/yyyy format. This line of code raises an error every time. With the checkbox property set to True, today's date becomes the default, which makes sense. But I still don't see the advantage (if any) of the checkbox.

    Thanks,
    Richard Barrett

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DTPicker (Word 2002)

    From Using the DateTimePicker Control (Visual Basic 6):
    Using The Checkbox to Select No Date
    The CheckBox property makes it possible to specify whether the control returns a date. By default, CheckBox is set to False and the control always returns a date.

    To enable the user to specify no date, set the CheckBox property to True (for example, if you are using the DateTimePicker to enter the completion date of a project but the project has not yet been completed).

    When CheckBox is set to True, a small check box appears in the edit portion of the control to the left of the date and time. If the box is not checked, the Value property returns a null value. If the user checks this checkbox, the control returns the displayed date through its Value property.

    More info on that page.

    Alan

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: DTPicker (Word 2002)

    Thank you. This makes sense now.

    I think I'm better off using the DT Picker with checkbox = false. But I'm not able to set the value of the control when my dialog displays. I see in the documentation which you sent, for example:

    dtStart.Value = "5/30/2005"

    This worked for me... once.

    dtStartValue = Format(Date, "m/d/yyyy"

    also worked... once. Since then, error 35788 is raised, desc. "An error occured in a call to the Windows date/time picker." Interestingly, when I just went back to test this again to get the proper wording, it functioned ONCE without error. I had previously exited and restarted Word, and on my first attempt I got the error. This was the second attempt of the session where thing functioned as expected. Try three was no good again.

    Any ideas on this? How best to I set the date value to today's date when I display the dialog. The property viewer shows 6/5/2005 as the value... which is the date I first created the control. It can't be blank unless chckbox = True. When that's the case, the value defaults to today's date. When checkbox = false, it would appear I need to set the value with code.... and that's not working.

    Thanks,
    Richard

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: DTPicker (Word 2002)

    In what context are you getting the error? Initialize routine? During or after a user update?

    I know it looks hokey, but I recommend using the Me object to get the autocomplete help for your controls. In a userform I created long, long ago, I set the value of the DTPicker this way (in Private Sub UserForm_Initialize()), in a dialog that has a "from" date and a "to" date. I'm pretty sure I didn't change the default for the "checkbox" property.

    Me.dPickFrom.Value = Format(CDate("01/01/" & Str(Year(Date))), "m/d/yyyy")
    Me.dPickTo.Value = Format(Date, "m/d/yyyy")

    Hope this helps...

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: DTPicker (Word 2002)

    I' get the error at Initialize. I've used code that is identical to you 2nd example. With the Me object, there is no difference. As I've mentioned, from time to time this works as expected without the error, so I'm guessing the problem is something other than the line of code.

    I've gone to two other PCs and tried this in Word XP and Word 2003, using code like my original code (which is your 2nd example). I haven't had a problem on those PCs with repeated attempts. It could, I suppose, be the template. I had already tried exporting and imported the form itself. I'll try deleting the controls and adding them anew. My next step will be to export everything and import them into a new template. I usually do that at the end of a project; in fact, I did it just a few days ago.

    Thanks.

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: DTPicker (Word 2002)

    Success! I deleted the DTPicker controls from the userform. I removed the DT Picker from the toolbox. I then re-added the DT Picker control to the toolbar, and replaced the controls in the userform. The code now works as expected.

    Thanks again for your usual valuable help.
    Richard

  7. #7
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: DTPicker (Word 2002)

    I discovered what was causing the error when I set the value of the DTPicker at the Activate event for the user form.

    Depending on choices the user makes in this user form, my code sets the visible property of the 2nd of the two DTPickers to True. (If a range of dates is appropriate, the Visible property of the dtEnd control is set to True. Otherwise, it remains False, which I set as a property at design time.)

    It seems this particular control must have Visible = True for the value to be se by code... otherwise an error is raised. (This occurs about 80% of the time. Occasionally, the error is not raised.) So I set the value to True in the Properties window. At Activate I set the value, and then set Visible = False. If the user make the appropriate selection for dtEnd to be displayed, it then displays as expected with the value I set.

    Richard

Posting Permissions

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