Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Forms / May 2006

Tip: Looking for answers? Try searching our database.

DTPicker GUI highlights date/month control was "created" vs. "toda

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
snsd - 09 May 2005 14:28 GMT
I am using DTPicker in a custom Task form and have it bound to the DueDate
field. I have the initial value of the control set to Date()+1. It seems to
be working fairly well. However, when I click on the drop-down arrow to open
the DTPicker calendar GUI, the highlighted value is the date I CREATED the
control versus TODAY's date. This wasn't a big deal when we were in the month
of April - the month I set-up the form - but now my users must always click
on the next month arrow to get to the month of May. Is there any way to have
the defaulted value within the DTPicker GUI (versus the control) highlight
today's date versus the date the control was created on? Thanks in advance
for any insight you might be able to share.

Dave
Eric Legault [MVP - Outlook] - 09 May 2005 20:21 GMT
Try setting the value of the DTPicker control when the form loads:

Function Item_Open()
    Set objDTP = Item.GetInspector.ModifiedFormPages("P.2").Controls("DTPicker1")
    objDTP.Value = Date()
End Function
   
Signature

Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

> I am using DTPicker in a custom Task form and have it bound to the DueDate
> field. I have the initial value of the control set to Date()+1. It seems to
[quoted text clipped - 8 lines]
>
> Dave
snsd - 09 May 2005 20:42 GMT
Eric: Thank-you so much for your response.

I'm pretty much a newbie and wanted to ask one point of clarification: Do I
just copy your code into the VB Script Editor behind the form? (I changed
"P.2" to my page name and "DTPicker1" to my control name.) I just want to
make sure I do it in VBScript and not in VBA. (Ideally, I'd like to keep it
in the form vs. VBA if possible.) I have copied it into the VB Script Editor
and it seems to run fine - but I won't be able to "see" if it works until
tomorrow after the date changes!

Hoping to hear back from you.

Dave

> Try setting the value of the DTPicker control when the form loads:
>
[quoted text clipped - 16 lines]
> >
> > Dave
Eric Legault [MVP - Outlook] - 09 May 2005 21:28 GMT
Yes, just paste into the VBScript editor.  You couldn't use VBA to do this
anyway.

If you want to test the control with a different date, replace the "Date()"
function with a value in the format #12/31/2005#.

Signature

Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

> Eric: Thank-you so much for your response.
>
[quoted text clipped - 30 lines]
> > >
> > > Dave
snsd - 10 May 2005 15:52 GMT
Eric:

Thanks for the code. It appears to have solved the initial challenge of
making sure that the calendar view displays “today” versus the day the form
was created. However, there is something I just can’t quite understand about
DTPicker and am hoping you might be able to help me with. (If you think I
should start a new post, please let me know and I will do so.)

Let me explain what I WANT to do and then I’ll explain what I’ve done.

What I want to do
 - Create control bound to due date field on custom task form
 - Set default value of control to Date() + 1
 - Allow users to change Due Date using DTPicker

What I’ve done
 - created control (txtDueDate) bound to Due Date field
 - on Values tab in Properties of txtDueDate control:
     “Property to use” = Value (is “Value” the right property for what I’m
trying to do?)
     “Set the initial value of this field to”: = Date() + 1
     “Calculate this formula when I compose a new form” button selected

 - created DTPicker control (DTPickerDueDate) bound to Due Date field; All
values in
   DTPicker are set to default values

 - code behind the form in VB Script (as suggested by you) to ensure that
DTPicker
   displays today’s date and not the date the control was originally created

        Function Item_Open()
             Set objDTP = Item.GetInspector.ModifiedFormPages("Client
Services Task
             Form").Controls("DTPickerDueDate")
             objDTP.Value = Date()
        End Function

Here’s where I need some help:

It appears that I need TWO controls: one for Due Date and one for DTPicker.
Is that correct? The reason I believe this is the case is because if I just
use the DTPicker and do not display the Due Date control, the DTPicker
control will display Date() even on a (non-new) record where I may have
previously set the due date to another date. i.e. create a new task; change
Due Date via DTPicker control to January 31, 2006; save task; when task is
opened, DTPicker control displays DATE() and NOT January 31, 2006.

So, here’s what I’ve done. I’ve sized the DTPicker control so that only the
drop down arrow appears and placed it beside the Due Date control. So, when
the user clicks on the drop down arrow, the DTPicker calendar pops-up and
they can select the date they desire. After selecting the date from the
DTPicker control, the Due Date FIELD is updated appropriately, but unless
another control on the form receives focus, the Due Date CONTROL does not
DISPLAY the updated value.

Two questions:

1) Is the way I’ve set-up the controls the best way to do so? i.e. are 2
controls necessary?

2) If “yes” to 1), what is the VB Script code I can add to the form to have
the focus set to the Due Date control (txtDueDate) AFTER the user selects a
date from the DTPicker control (DTPickerDueDate) so that the user can see
that the Due Date has been updated without having to manually select another
control?

I apologize for the length of this post – but wanted to give all relevant
information.

Thanks in advance for any further help you might be able to give.

Dave

> Yes, just paste into the VBScript editor.  You couldn't use VBA to do this
> anyway.
[quoted text clipped - 36 lines]
> > > >
> > > > Dave
Eric Legault [MVP - Outlook] - 10 May 2005 16:32 GMT
First off, I was incorrecting in stating in my last post that you cannot
access the controls on your custom form from VBA - you indeed can by using
the Inspector.GetModifiedFormPages("PAGENAME").Controls collection.

Boy, you've got me quite confused.  Are you just trying to set the default
DueDate value on the main page to the day after when a new instance of the
form is opened?  If so, adding this code will do what you want, with no
custom controls required:

Function Item_Open()
    Item.DueDate = DateAdd("d", 1, Date())
End Function

Why do you need a custom DTPicker control anyway when the one for DueDate is
perfectly okay?

Also keep in mind that if you have multiple controls bound to the same
field, setting the value of the property (i.e. TaskItem.DueDate) will cause
this value to appear automatically in every control that is bound to it.  The
same goes in reverse - changing the value in the control at run-time will
cause all controls bound to that field to update with the same value.  
However, the DTPicker control is different - it does not automatically
reflect these changes in both directions, so you have to be careful.  When
the user saves the item, you have to manually get the value from that control
and save it to the field it is bound to.

If you are tracking two different kind of dates, then you definitely need a
custom field to bind one of the controls to.

Does this help at all?

Signature

Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

> Eric:
>
[quoted text clipped - 110 lines]
> > > > >
> > > > > Dave
snsd - 10 May 2005 17:31 GMT
Eric:

Thanks again for your response.

Sorry for the confusion. It’s really simple what I’m trying to accomplish.
Hopefully I can be more clear….

My users need to update a number of fields (including custom fields I've
created) that are not available on Page 1 of the standard Task form. Rather
than requiring them to tab to Page 2 on my custom form to update these
fields, I decided to hide Page 1 and replicate the controls that we require
from Page 1 onto Page 2. The ONLY control I’m having a challenge with is
DTPicker. So…

Bottom line: I am NOT trying to track two kinds of dates. I simply want to:

1) replicate the Due Date control including the date picker from Page 1 of
the standard form onto page 2 of my custom form
2) Default the value of the Due Date control (and bound Due Date field) to
Date() + 1 when a NEW instance of the form is created.

I was hoping that it’s as simple as binding the DTPicker control to Due Date
and setting it’s default value to Date() + 1. Unfortunately, it seems more
involved than that.

Hope that makes it more clear.

Look forward to getting to the bottom of this.

Dave

> First off, I was incorrecting in stating in my last post that you cannot
> access the controls on your custom form from VBA - you indeed can by using
[quoted text clipped - 141 lines]
> > > > > >
> > > > > > Dave
Eric Legault [MVP - Outlook] - 10 May 2005 18:46 GMT
Okay, I understand now.  Try this:

Bind the DTPicker control to the DueDate field.  Put this in the "Set the
initial value of this field to:" box, and select "Calculate this formula when
I compose a new form":

DateAdd("d", 1 , date())

Now add this code behind the form:

Function Item_Open()
    Item.Getinspector.ModifiedFormPages("P.2").Controls("DTPicker1").Value =
Item.DueDate
End Function

Since the DTPicker1 control doesn't automatically detect the change to the
DueDate field when the form opens, even when it is bound, you have to read it
in manually to detect the change by the formula.  You can also detect changes
to intrinsic fields by trapping the field name in the Item_PropertyChange
event, but this isn't fired by the application of the formula.

Signature

Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

> Eric:
>
[quoted text clipped - 172 lines]
> > > > > > >
> > > > > > > Dave
snsd - 10 May 2005 19:42 GMT
Bingo!!!

Thanks Eric. I'm confident you've given me the solution I need. The only
clarification I want to make (ask?) for the sake of other users perusing this
post is that the "Property to Use" on the Value Table of the control's
property dialogue box is "Value". (Its default value is "blank".)

Thanks again for your incredible patience, fast response time, and most of
all your commitment to helping me find the right solution.

Till next time...

Dave :)

> Okay, I understand now.  Try this:
>
[quoted text clipped - 193 lines]
> > > > > > > >
> > > > > > > > Dave
snsd - 10 May 2005 20:02 GMT
Eric:

OK. One small hitch that I'm assuming just requires a minimal tweak.

I created a new task item using the form and saved it. When I open the item,
all is fine. When I close it, it prompts me to save it even if I haven't
updated any controls. What do we need to add to stop the prompt to save the
item?

Thanks again. Hopefully this will be my last question on this issue.

Dave

> Bingo!!!
>
[quoted text clipped - 207 lines]
> > > > > > > > >
> > > > > > > > > Dave
Eric Legault [MVP - Outlook] - 10 May 2005 21:11 GMT
Strange, I'm not getting the same behaviour.  Anyway, if something has
changed, this will save it silently:

Function Item_Close()
    If Item.Saved = False Then
                    Item.Save
    End If
End Function

Signature

Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

> Eric:
>
[quoted text clipped - 220 lines]
> > > > > > > > > >
> > > > > > > > > > Dave
snsd - 10 May 2005 21:56 GMT
Whew!

That does it.

Eric: Thank-you sooooooooooooooo much. My users will love it!

Dave

> Strange, I'm not getting the same behaviour.  Anyway, if something has
> changed, this will save it silently:
[quoted text clipped - 229 lines]
> > > > > > > > > > >
> > > > > > > > > > > Dave
snsd - 11 May 2005 15:46 GMT
Eric:

Me again.... I know once we’ve nailed this one down that others will benefit
from the information….

I’ve discovered a couple of bugs.

Before I explain the bugs, I want to explain EXACTLY what I’ve done. I
believe I’ve followed your instructions precisely. (I started with a blank
standard form just to make sure that other code in my form wasn’t
interfering.)

Inserted DTPicker control on P.2
Bound DTPicker1 control to “Due Date” field
“Property to use:” set to “Value”
"Set the initial value of this field to:" DateAdd("d", 1 , date())
Select "Calculate this formula when I compose a new form"

Code added behind the form
Function Item_Open()
    Item.Getinspector.ModifiedFormPages("P.2").Controls("DTPicker1").Value =
Item.DueDate
End Function

If I run the form from the design window WITHOUT PUBLISHING IT FIRST, all is
well. In other words, if I save the item, reopen it, close it (without any
changes to the item), it closes without prompting me to save it.

However, once I publish the form, if I create a new item using the newly
published form, save it, open it, close it (without any change to the item),
it prompts me to save it.

I tried this two or three times and continue to get the same result ONLY
AFTER PUBLISHING it. I mention this because you mentioned that you couldn’t
replicate the issue. I’m curious as to whether you actually published the
form or whether you just ran it from the design window.

OK. So, to solve this challenge, we added the suggested code:

Function Item_Close()
    If Item.Saved = False Then
                    Item.Save
    End If
End Function

While the code solved the challenge of being prompted to save an item that
hadn’t been modified, it has introduced two new challenges:

1) If you DO modify a record and press ESC or click the “X” close button, it
automatically closes AND saves the item. Usually, when you use ESC or click
the close button, Outlook prompts you to save the item. We need to determine
a workaround for this issue as we don’t want to have all other Outlook items
function one way and this one does something different.

2) I didn’t mention this earlier as it wasn’t an issue until we added the
Item_Close function… I think there is a challenge with the Item_Close
function when a validation rule on a control is set so that the control must
contain a value. I’m not 100% certain that it happens ONLY when there are
mandatory controls on a form, (i.e. it may just be a coincidence and the
underlying issue may be something else altogether) but the challenge
replicates itself 100% of the time when there are mandatory controls on a
form.

To replicate the challenge on your PC, add the Mileage control to P.2 and
set the validation rule so that the control requires data. Publish the form.
Open the form and hit the ESC key. The Script Error “Unable to save this
item. Line No:7” appears. The error appears every time you try to close the
form without completing the mandatory controls. It seems that the error
message is innocuous but I don’t want our users to be bothered by it. I want
them to see the custom messages I’ve created stating which control requires a
value. I don’t know a lot about VB Script, but if we put the validation rules
in VB Script versus in the property control properties, could that suppress
this error? If so, could you possibly let me know the code for making the
Mileage control mandatory (and a corresponding error message) and I can adapt
it to my form?

Again, I apologize for the length of this post, but I believe all the
details are necessary.

Dave

> Whew!
>
[quoted text clipped - 231 lines]
> > > > > > > > > > > > control versus TODAY's date. This wasn't a big deal when we were in the month
> > > > > > > > > > > > of April - the month I set-up the form - but now my users must always click
Michelle - 30 May 2006 17:22 GMT
Hi there,
I was hoping to get assistance on the simplest thing in Outlook 2003.  I
have changed the view that I would like to have my program open to but it
does not hold the change.  I have not seen this happen before and am not sure
if this is a default setting I am not familiar with.  Your input and
suggestion will be most appreciated.
Kind regards,
Michelle

> Eric:
>
[quoted text clipped - 251 lines]
> > > > > > > > > Due Date via DTPicker control to January 31, 2006; save task; when task is
> > > > > > > > > opened, DTPicker control displays DATE() and NOT January 31, 2006.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.