Hi Fred,
Complete these steps so you can see how this works - then you can work on
implementing this in your solution.
- Create a new, blank InfoPath solution
- From the Tools menu, choose Form Options
- Select the Advanced tab
- Make a note of what Programming Language is specified so you can use the
appropriate code sample below
- Click OK or Cancel to close the window
- Display the Controls Task Pane
- Add a Drop-down List Box and a Text Box to the form (they should be named
"field1" and "field2" respectively)
- Right-click on the Drop-down List Box and choose Properties
- Click the Add button to add entries to the list box - add some entries to
this control and then leave this screen open
- Click the Data Validation button
- From the "Events" box select OnAfterChange
- Click the Edit button
- If you noted the Programming Language as VBScript, then add the following
code just before the "End Sub" line:
If eventObj.Operation = "Insert" Then
Dim objField2
Set objField2 = XDocument.DOM.selectSingleNode("//my:myFields/my:field2")
If objField2.text = "" Then
objField2.text = eventObj.Site.text
Else
objField2.text = objField2.text & ", " & eventObj.Site.text
End If
Set objField2 = nothing
End If
If you noted the Programming Language as JScript, then add the following
code immediately before the last "closing brace" ("}"):
if(eventObj.Operation == "Insert")
{
var objField2 = XDocument.DOM.selectSingleNode("//my:myFields/my:field2");
if(objField2.text == "")
{
objField2.text = eventObj.Site.text;
}
else
{
objField2.text = objField2.text + ", " + eventObj.Site.text;
}
objField2 = null;
}
- Save and close the Script Editor window (this should put you back to your
InfoPath form)
- Preview the form and make a selection from the drop-down box. The first
time, it should add the text to the box - subsequent times it should
"append" the selection to the existing text.
I hope this helps!
Best Regards,
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Fred Lopez - 05 Aug 2005 18:50 GMT
Scott, that worked. I totally missed the onafterchage box the first time!
Thanks so much!
Kenneth - 05 Aug 2005 22:41 GMT
Hi Scott,
Really admire your patience when I read your answers. It is in such details
that for sure a big help for novice.
> Hi Fred,
>
[quoted text clipped - 63 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
KLaw - 10 Aug 2006 17:17 GMT
Hi Scott:
I am trying to use this solution that you recommended last year and it's
exactly what I need. However, I keep getting a error: I'm using VScript and
this line is giving me an issue: if(objField2.text == "") The error says
I'm missing an object. I am not a programmer, hence my confusion. Should
there be two equal signs? Do I need to put something in between the quotes?
Do I need to replace Field2 with my field name in every line? I've tried all
of these options and still get an error.
Any help is surely appreciated.
Kammy
> Hi Fred,
>
[quoted text clipped - 63 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
Greg Collins [InfoPath MVP] - 10 Aug 2006 21:02 GMT
You said you are using VBScript, yet the syntax you show is for JScript.
JScript: if(objField2.text == "")
VBScript: If objField2.text = "" Then

Signature
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Visit InfoPathDev ( http://www.InfoPathDev.com )
S.Y.M. Wong-A-Ton - 11 Aug 2006 06:29 GMT
If the error says that you're missing an object, probably "object required",
objField2 is not an object. I'm assuming that you have an XPath somewhere to
retrieve the node corresponding to objField2. Check to see whether this XPath
is correct.
if(objField2.text == "")
should be in VBScript
If objField2.text = "" Then
...
End If
---
S.Y.M. Wong-A-Ton
> Hi Scott:
>
[quoted text clipped - 77 lines]
> >
> > This posting is provided "AS IS" with no warranties, and confers no rights
BostonCC - 25 Apr 2007 16:26 GMT
Man! - that was some great technical help - Awesome Job Scott.
I have one question to add to this:
where in that code can I insert (and what code for that matter) something to
be able to separate the value/list that the person chooses?
For example, in your code, as the person chooses different values, in the
text box, it runs them continuosly, i.e., Value1, Value2, Value3, (like a
sentence) etc...
I need mine to be listed vertically.....i.e.,
value1
value2
value3, etc.
Ideally, if each value chosen would start with a bullet or a dash, that
would be even better
: )
Just from hanging around this forum I've learn so much - it's great that its
available.
To all of you who provide us "non Tech" folks the answers - THANK YOU!!!! -
It's greatly appreciated......
> Hi Fred,
>
[quoted text clipped - 63 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
BostonCC - 26 Apr 2007 13:00 GMT
Does anyone have an answer? Thanks
> Man! - that was some great technical help - Awesome Job Scott.
>
[quoted text clipped - 91 lines]
> >
> > This posting is provided "AS IS" with no warranties, and confers no rights