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 / General MS InfoPath Questions / June 2006

Tip: Looking for answers? Try searching our database.

Receive error when trying to populate date picker by code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jamz68 - 30 Jun 2006 16:23 GMT
Here is the error I get when I attempt to populate a date/time using code in
an empty date picker.

The following error occurred:

'#PCDATA' is in nil content:
<{http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-06-08T22:20:43}date2>.

If I populate the date/time manually prior to running the code it updates
normally but I would like to avoid this extra step.
Greg Collins [InfoPath MVP] - 30 Jun 2006 21:06 GMT
Your date field is allowed to have no value. This means that in the XML it has an attribute on it (xsi:nil="true"). This attribute tells InfoPath that it is okay for this non-string data-type field (i.e. a date-type field) is allowed to have no value. Normally non-string fields cannot be blank. Thus this attribute.

You need to, in code, first remove the xsi:nil attribute (if present) and then set your field value, because the two cannot be present at the same time: either it is NIL or it has a value -- not both.

Then if you ever set your field back to blank, you must add the xsi:nil attribute back to the node, or you'll get an error in the form stating that it is a required field and cannot be blank.

Signature

Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Visit InfoPathDev ( http://www.InfoPathDev.com )

Jamz68 - 30 Jun 2006 22:46 GMT
Thanks Greg for your assistance. I tried what you suggested. It did allow me
to set the date without first having the field populated, however it broke
the control. It only displays the date now instead of date and time. I
managed a workaround however. Using a rule, I set the value of the second
date picker from the first then I was able to adjust the start and ending
time for the appointment with code by parsing the field contents and saving
it back into the field after changing it.

> Your date field is allowed to have no value. This means that in the XML it has an attribute on it (xsi:nil="true"). This attribute tells InfoPath that it is okay for this non-string data-type field (i.e. a date-type field) is allowed to have no value. Normally non-string fields cannot be blank. Thus this attribute.
>
> You need to, in code, first remove the xsi:nil attribute (if present) and then set your field value, because the two cannot be present at the same time: either it is NIL or it has a value -- not both.
>
> Then if you ever set your field back to blank, you must add the xsi:nil attribute back to the node, or you'll get an error in the form stating that it is a required field and cannot be blank.
Greg Collins [InfoPath MVP] - 30 Jun 2006 23:40 GMT
Removing xsi:nil is mandatory if you want to set a value. It does not "break" the control--in fact it does not effect the control, just the data node in the XML.

Double check that your control is set to show both date and time, and then double check that the value you are setting via code is in the correct XML data/time format:

yyyy-MM-ddTHH:mm:ss

Signature

Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Visit InfoPathDev ( http://www.InfoPathDev.com )

 
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.