Assigning a value to a field

C

Chris K

I am having a difficult time and I'm sure that it isn't too difficult!

I am trying to assign a value to a field on an infopath form. I have no
problem doing so when the form is created using xml as the data repository.

My problem is when i create a form using a SQL database as the repository.
Can someone point me to example code that uses this backend? If I have not
provided enough info let me know what else you need.

Thanks
 
S

Scott L. Heim [MSFT]

Hi Chris,

I would like to get some additional information from you:

- What action is triggering the update? For instance, are you making a
selection from a drop-down box where you would like to populate other
fields based on the selected item?
- Are your fields in a Repeating Section or Table?

I simply want to get a better overview of what you have implemented so we
can provide the best solution.

Thanks Chris!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Chris K

Hi,
Here is some additional info.

The trigger can be a button control. I would like to put a value in the
Reporting_D field, it is Reporting Date. The reporting_d field is inside a
repeating section that is bound to the d:project_status_report group.

My Data Source pane looks like and is generated from a SQL DB.

myFields
queryFields
dataFields
d:project_Status_Report (a repeating group folder)
Project_ID
Reporting_D (data type is date Time.notz)
More groups...

Thanks for the help.
 
S

Scott L. Heim [MSFT]

Hi Chris,

Thank you for the additional information. The easiest way to accomplish
this since you have a Repeating Section is to place a button in that
Repeating Section that would be used for setting the date value. So based
on that, here is sample code used to set an OrderDate field that comes from
SQL Server:

Dim objOrderDate As IXMLDOMAttribute
objOrderDate = e.Source.selectSingleNode("@OrderDate")
objOrderDate.text = Format(Date.Today, "yyyy-MM-dd")

You will notice the "@" symbol in front of the OrderDate field - this
indicates the field is an attribute. You will want to confirm this in your
date source Task Pane: right-click on your date field, choose Properties
and look at the "Type" - if it indicates "Attribute" you will need to
include the "@" symbol as well.

Let me know if this helps!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Chris K

Hi Scott,

Thank you very much for this tip. I got it working.

The service you provide in this forum is AMAZING!

Chris
 
S

Scott L. Heim [MSFT]

That's great Chris - thank you for the update!

Best regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Chris K

Ok, I am back. What you suggested worked great for that scenario, but when I
tried something similiar the framework did not work.

I am trying to modify the 'Create new record' button to assign a value from
a query field 'Field a' to the data field version of 'Field a'.

It appears that assigning values to fields is a very delicate process with
many implementation paths depending on the scenario. Can you recommend some
resources to help me figure out the best way to research questions like this
- Books, blogs, websites, ... ?

Thanks
 
S

Scott L. Heim [MSFT]

Hi Chris,

I understand - getting a handle on XPATH expressions takes a bit of time so
please give yourself that time! :)

One of the things that most folks have an issue with is the "namespace"
that needs to be referenced in your XPATH. For instance, when you are bound
to Access or SQL, the namespaces are typically "dfs" and "d" whereas when
you are bound to a web service, you will normally see "dfs" and "tns."

One of the ways you can determine this is to use the Expression Box
control. When you select this control, you will see the "fx" button -
simply click this button, click the Insert Field or Group button, navigate
to the field you need to reference, click OK and then click the "Edit
XPath" box - this will now show you the complete XPath including the
namespace information!

Now this is not a guaranteed solution 100% of the time but it will get you
where you need probably 90% of the time.

With regard to where to get help - I would suggest looking for a book that
is deep into XPATH expressions. These are not specific to InfoPath - they
are specific to XML so you can use this information outside of InfoPath as
well. In addition, the following should help as well:

InfoPath BLOG Site
http://blogs.msdn.com/infopath/

InfoPath Developer Site
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/ht
ml/odc_ancinfo.asp

InfoPath FAQ
http://www.microsoft.com/technet/prodtechnol/office/office2003/plan/inpthfaq
..mspx

InfoPath SDK
http://www.microsoft.com/downloads/details.aspx?FamilyId=351F0616-93AA-4FE8-
9238-D702F1BFBAB4&displaylang=en

InfoPath Technical FAQ
http://www.microsoft.com/technet/prodtechnol/office/office2003/plan/inpthfaq
..mspx#ECBAA

InfoPath Training
http://msdn.microsoft.com/office/understanding/infopath/toolsandcode/default
..aspx?pull=/library/en-us/odc_2003_ta/html/odc_landinfo03_tr.asp

MSDN XML DOM Documentation
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html
/e9da2722-7879-4e48-869c-7f16714e2824.asp

Xpath Sample Expressions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html
/daa75346-ccd1-4033-9250-9b9f3ba5762c.asp

Best regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Top