M
Marc Nemegeer
Hi,
Is this possible ? And how can be it be done ?
Thanks,
Marc
Is this possible ? And how can be it be done ?
Thanks,
Marc
Scott L. Heim said:Hi Marc,
OK - try these steps as documented to see if they provide you with what you
need!
- Create a new Access database named SelectedItemsTest.MDB
- Add a table (named Table1) with the following fields:
- ID (AutoNumber, Primary Key)
- MyDesc (Text)
- Selected (Yes/No)
- Add the following data entries to the table: Desc1, Desc2, Desc3, Desc4,
Desc5
- Create a new, blank InfoPath solution
- Add a secondary data connection to Table1
- From the Data Source Task Pane, select the Table1 Secondary Data Source,
expand dataFields, drag d:Table1 to your form and select Repeating Table.
- Select the Controls Task Pane
- Add a button below the table
- Add a Repeating Table to your form with just 1 field - your "Main" data
source should appear as follows:
- myFields
- group1
- group2
- field1
- Right-click on the button, choose Properties and click the Edit Form Code
button
- You should see the following:
function CTRL8_5::OnClick(eventObj)
{
}
- Add this code between the braces:
//Get a reference to the Table1 data connection
var objTable1DOM = XDocument.GetDOM("Table1");
//Set the SelectionNamespaces property of the Table1 data connection to
walk the DOM
objTable1DOM.setProperty("SelectionNamespaces",
'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSoluti
on" ' +
'xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"'
);
//Get the selected items
var objSelectedItems =
objTable1DOM.selectNodes("//dfs:myFields/dfs:dataFields/d:Table1[@Selected
= 'True']");
//Loop through the selected items
for(i=0;i<=objSelectedItems.length -1;i++)
{
//See if the first record in the destination Repeating Table is blank
if(XDocument.DOM.selectSingleNode("//my:group1/my:group2/my:field1").text
== "")
{
XDocument.DOM.selectSingleNode("//my:group1/my:group2/my:field1").text =
objSelectedItems(i).attributes(1).text;
}
else
{
//Add a new row
XDocument.View.ExecuteAction("xCollection::insert", "group2_1");
//Get a reference to that new row
var objNewItem =
XDocument.DOM.selectSingleNode("//my:group1/my:group2[last()]/my:field1");
//Set the text of the field
objNewItem.text = objSelectedItems(i).attributes(1).text;
}
}
- ** NOTE: In the ExecuteAction line, you will see a reference to: group2_1
- you will want to insure this is the same in your sample. Right-click on
the destination Repeating Table, choose Properties and then select the
Advanced tab - this will confirm your collection value.
- Save the code and test - you should be able to select 1 or more items
from the secondary data source table and add those to your main form table!
Now you may need to expand on this as I am not taking into consideration if
you immediately go back and add another selection that we just add that new
item. But this should at least get you going.
Let me know how this works for you!
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.