word 2010 forms, advanced features
-
vendredi 13 juillet 2012 05:40
hello! i'm very new, forgive me if this question seems ignorant. my endeavor at the the moment is make a form that minimizes user error and tedium in my line of work. thus, if you can imagine, i'd like to have a form that selecting an option from the drop down menu will correspond to another option in a separate drop down menu. I've just recently watched lynda.com's forms in depth training which was a big help. essentially, i'm aiming for a form/schema set-up that repeats data. But instead of repeating data, it put up a different yet appropriate block of text, that can be user changeable (I don't like that all the schema related text are permanently linked such that custom text can't be entered by the user)
any step in the right direction would be a big help and a huge relief. thanks
Toutes les réponses
-
vendredi 13 juillet 2012 06:24Modérateur
Hi tonayie
It would help us envision what you have in mind if you could give us a small example?
Do I understand correctly that this should be on the document surface, not in a dialog box or task pane?
And everything should be editable by the user?
Is my understanding correct that you have no programming experience of any kind?
Cindy Meister, VSTO/Word MVP
-
vendredi 13 juillet 2012 07:07Cross-posted at: http://answers.microsoft.com/en-us/office/forum/office_2010-word/word-2010-forms-help/4fb1dae0-3583-49d5-9f1c-0594ad5edf38For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
Cheers
Paul Edstein
[MS MVP - Word] -
vendredi 13 juillet 2012 14:08
yes, i don't have much experience with programming. but i'm willing to go through the means necessary. and yes i would love it to be on the document surface of it's possible.
yes, here's an example (but not my real intent): here's my form with 2 fields: name and gender. let's say in the drop-down menu for name there's a field for "Mr." and "Mrs". then in the gender part, it automatically adjusts to male or female depending on the title chosen - such things might be useful i someone has to do this....say 1000 times. Is something like this at all possible?
.....................
I've been doing some more research, do you think this is something more suited for infopath?
Also, I saw your very helpful post: http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/4e7c4129-6eb3-4549-8f2b-8bcb756f0c99
Is that a similar task that I am trying to achieve?
- Modifié tonayie vendredi 13 juillet 2012 14:18
-
vendredi 13 juillet 2012 14:54Modérateur
Hi tonayie
Thank you for the additional information :-) What you describe is possible, it's only a matter of figuring out the best approach. Since you've seen the recent discussion on a similar question, you know the kinds of questions I want to ask you at this point:
1. Should the user be able to edit freely in the document, or only use the fields?
2. What do you want to do with the information in the document? Print it out? Extract it into a data base or some other application? Something else?
3. When a selection is made that should populate another part of the document, where should this information / these lists be coming from? It's rarely a good thing to hard-code them; usually, it's better to read them from an outside source that can be more easily managed than re-writing code.
Cindy Meister, VSTO/Word MVP
-
vendredi 13 juillet 2012 15:35
1. yes, it would be fantastic if the user could edit freely in the document, and the fields too - like combo boxes, i suppose. for instance to put "Dr." if it wasn't available in the drop down.
2. Print it out. It might be sent elsewhere as docx files or otherwise and shared among-st personnel and re-edited by higher-ups. but printing them out is the first priority.
3. honestly i'm not quite sure what is meant here. up till now, i've assumed that the "lists" would be part of the document when made. But if it can be done any other way that doesn't give gravely disparate results, i'd take no issue.
-
lundi 16 juillet 2012 10:15Modérateur
Hi tonayie
RE Infopath: If these documents are mainly to be printed and shared among personell, then InfoPath is not the correct tool. That is mainly for gathering data that will be stored in a database and processed in various ways.
There is no content control that can function like a combo box. You could use an ActiveX combobox (the same control that can be placed on a UserForm), but there can be issues with using ActiveX. It might be better to have a separate interface for adding things to the dropdown list(s). A button on the Ribbon that displays a UserForm, for example.
Point 3 follows up on this: the origin of the entries in the lists and managing the entries in the lists. Going back to an earlier reply you said, if the user selects Mr. or Ms. then the gender should be set to Male or Female - no problem there. But if people can start adding things to the lists, and you want to also support associations with other things, then you will either need to change the code everytime something should be added, or the lists need to be maintained another way and the code will need to have logic in it in order to sort the lists and make the necessary associations.
Or, to put it another way, a lot depends on how static vs. dynamic the functionality of the form should be.
If you're happy with "static", then you can basically use the same approach in that other post you mention.
Cindy Meister, VSTO/Word MVP
-
mardi 17 juillet 2012 23:55i think i'm making progress. one question though. is there a way to limit content control action in code to a specific page, like the active page? my form tends to be repeated well over 40 times in the same document. i'd like conditional values set per form in a document, not influencing every identical content control in the document. is this impossible?
-
mercredi 18 juillet 2012 01:14
Cindy,
"There is no content control that can function like a combo box ..."
????
I do this all the time to automatically add text entered into a CC combobox to the list of available choices.
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim i As Long
Dim bInList As Boolean
Dim arrTitles() As String
Select Case CC.Title
Case "Title"
For i = 1 To CC.DropdownListEntries.Count
If CC.Range = CC.DropdownListEntries(1).Text Then
Exit Sub
End If
Next i
CC.DropdownListEntries.Add CC.Range.Text, CC.Range.Text
ReDim arrTitles(CC.DropdownListEntries.Count - 1)
For i = 1 To CC.DropdownListEntries.Count
arrTitles(i - 1) = CC.DropdownListEntries(i).Text
Next i
WordBasic.SortArray arrTitles(), False
CC.DropdownListEntries.Clear
For i = 0 To UBound(arrTitles)
CC.DropdownListEntries.Add arrTitles(i), arrTitles(i)
Next i
End Select
End SubGreg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
-
mercredi 18 juillet 2012 16:26Modérateur
Hi Greg
<duh> I was only seeing the dropdown list yesterday. You're right, of course.
Cindy Meister, VSTO/Word MVP
-
mercredi 18 juillet 2012 16:33Modérateur
<<is there a way to limit content control action in code to a specific page, like the active page?>>
Mmm, possibly. If you look at that other discussion you see (again, near the very end) where I use Range.InRange to check whether the content control is "in the right place"?
The tricky part is getting the range of a page, because Word doesn't really work with "pages" as true objects. A "page", like a "line", is something very dynamic and depends on the page flow layout at any particular moment. This in contrast to a paragraph, which can be identified by a specific character.
There is a way to get a Range of a page, but it may not be 100% accurate (might "slip over" to the previous or next page). You'd need to try it. The following line of code gets a range for the currently active page. That means the selection actually needs to be on the page you want to pick up - probably not a problem for your scenario.
Set rngPage = ActiveDocument.Bookmarks("\Page").Range
So you can test whether a ContentControl.Range is in the rngPage.
Cindy Meister, VSTO/Word MVP
-
mardi 24 juillet 2012 02:47
I think your problem is that you are refering to histology as a group of content controls with like titles instead of a specific CC.
Get rid of the For ... Each ... Next loop.
Change Word.ContentControls to Word.ContentControl and Set histology = ActiveDocument.SelectContentControlsByTitle("histo")
to Set histology = ActiveDocument.SelectContentControlsByTitle("histo").Item(1) or whatever item it is. Or use:
Set histology = ActiveDocument.ContentControls("XXXXXXXX")
Where "XXXXXXXXX" is the unique CC ID that you can get using:
Sub GETCCUniqueID()
MsgBox Selection.Range.ContentControls(1).ID
End Sub
Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
-
mardi 24 juillet 2012 03:02the cc id thing looks promising but i don't see how i can utilize it if i must know the index as well. the form would be copied and pasted multiple times in the same document. As is, the code works as i'd expect it do. it's just that i want it to be possible for different columns to have different results depending on the input.
- Modifié tonayie mardi 24 juillet 2012 03:04
-
mardi 24 juillet 2012 03:13
You can get the unique ID of any CC by selecting it and running the GetCCUniqueID code.
While you can have many CCs with the same title, each can have a unique Tag. So you could:
For Each oCC in oCCs
If oCC.Tag = "Column 1" Then
...
Or something like this might work:
Sub ScratchMacro()
Dim oRng As Word.Range
Dim oCCs As ContentControls
Dim oCC As ContentControl
Set oCCs = ActiveDocument.SelectContentControlsByTitle("Name")
ActiveDocument.Tables(1).Columns(2).Select
Set oRng = Selection.Range
For Each oCC In oCCs
If oCC.Range.Information(wdEndOfRangeColumnNumber) = Selection.Range.Information(wdEndOfRangeColumnNumber) Then
oCC.Range.Text = "Write text to me."
End If
Next
End SubGreg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
-
mardi 24 juillet 2012 03:27i'm not sure i follow, here i have to specify the table and column to select and i want to avoid that because i won't do the selecting, the user will. is this something that might be fixable with a set rngpage = command like the one above?
-
mardi 24 juillet 2012 03:53Word will tell you what CC, what table, and what column the uses exited:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oRng As Word.Range
Dim oCCs As ContentControls
Dim oCC As ContentControl
Dim lngCol As Long
Set oCCs = ActiveDocument.SelectContentControlsByTitle(ContentControl.Title)
lngCol = ContentControl.Range.Information(wdEndOfRangeColumnNumber)
For Each oCC In oCCs
If oCC.Range.InRange(Selection.Tables(1).Range) And oCC.Range.Information(wdEndOfRangeColumnNumber) = lngCol Then
oCC.Range.Text = ContentControl.Range.Text
End If
Next
End SubGreg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
-
mardi 24 juillet 2012 04:03
thank you very much for that code. i will try to implement it, but i think something just hit me. I could probably just make about hundred instances of your code right? having the first primary.item(1) affect secondary .item(1) and simply repeat them for 100 items? how does that sound? how would that code look? does it sound plausible. please let me know, i think i'm on a break-through!
edit: nevermind, haha. the members have to exist before i can refer to them it seems.
Anyway I've tried your code but I get an error 6124: you are not allowed to edit this selection because it is protected.
"oCC.Range.Text = ContentControl.Range.Text"
I think i'll try more along the lines of what my proposal was. more because i understand it.
- Modifié tonayie mardi 24 juillet 2012 04:39
-
mardi 24 juillet 2012 11:16
You are getting that error most likely because you are working with a dropdown field where my example, for simplicity was using a plain text field, the principle is the the same, you just need to put the loop back in:
Select Case ContentControl.Range.Text
Case "1"
oCC.DropdownListEntries.Item(1).Select
Case "2"
oCC.DropdownListEntries.Item(2).Select
Case "3"
oCC.DropdownListEntries.Item(3).Select
Case "4"
oCC.DropdownListEntries.Item(4).Select
End SelectGreg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
-
mardi 24 juillet 2012 12:09
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Dim histology As Word.ContentControl Dim oCCs As Word.ContentControls Dim oCC As Word.ContentControl Dim eti2 As String Dim lngCol As Long Set oCCs = ActiveDocument.SelectContentControlsByTitle(eti2) lngCol = ContentControl.Range.Information(wdEndOfRangeColumnNumber) For Each oCC In oCCs If oCC.Range.InRange(Selection.Tables(1).Range) And oCC.Range.Information(wdEndOfRangeColumnNumber) = lngCol Then oCC.Range.Text = ContentControl.Range.Text Set histology = ActiveDocument.SelectContentControlsByTitle("histo").Item(1) Select Case ContentControl.Range.Text Case "1" histology.DropdownListEntries.Item(1).Select Case "2" histology.DropdownListEntries.Item(2).Select Case "3" histology.DropdownListEntries.Item(3).Select Case "4" histology.DropdownListEntries.Item(4).Select End Select End If Next End SubHere is the code exactly as I have it. i get that error and it seems to be referencing the wrong content control. regardless, i'm not sure that this is the way to go since, i have to specify the table number in the code, even though there will multiple copies of that same table in the document.- Modifié tonayie mardi 24 juillet 2012 12:10
-
mardi 24 juillet 2012 23:31
You are getting the error because you are trying to set a range.text value in a dropdown content control!
oCC.Range.Text = ContentControl.Range.Text
You are also moving the goal post after the start of the game!!.
Dim eti2 As String
What is eti2? You declare a variable named that but you don't provide the variable value.I still don't know exactly what it is that you want to do, but from reading the earlier posts it seems like you want to select a value from a CC in a table column and have that selection set the value of another CC in the same table and same column named "histology" I have tried to avoid giving you the fish, but I am tired of giving fishing lessons so here is the fish:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oCCHistology As Word.ContentControls 'This is the collection of all CCs in the document titled "Histology"
Dim oCC As Word.ContentControl 'This is just a single CC object.
Dim lngCol As LongSelect Case ContentControl.Title
'This case runs if the "ContentControl" that you are exiting is titled as shown.
Case "Some CC That You Want to Effect Histology"
'This is all the CCs with a title "Histology" no matter where they are.
Set oCCHistology = ActiveDocument.SelectContentControlsByTitle("Histology")
'This finds out which column "ConentControl" is in.
lngCol = ContentControl.Range.Information(wdEndOfRangeColumnNumber)
For Each oCC In oCCHistology
'If the oCC is in same table as "ContentControl" and in the same column then ..
If oCC.Range.InRange(Selection.Tables(1).Range) And oCC.Range.Information(wdEndOfRangeColumnNumber) = lngCol Then
Select Case ContentControl.Range.Text
Case "1"
oCC.DropdownListEntries.Item(1).Select
Case "2"
oCC.DropdownListEntries.Item(2).Select
Case "3"
oCC.DropdownListEntries.Item(3).Select
Case "4"
oCC.DropdownListEntries.Item(4).Select
End Select
End If
Next oCC
Case Else
'
End Select
End SubGreg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
- Marqué comme réponse tonayie mercredi 25 juillet 2012 01:39
-
mercredi 25 juillet 2012 01:42
i can't believe it. i dunno, what you did, i dunno what i missed, but it 100% works. i am completely, totally, inordinately, unequivocally indebted to you. .."Tables(1) kept throwing me off.
- Modifié tonayie mercredi 25 juillet 2012 01:42
-
mercredi 25 juillet 2012 02:04
Buy a kid and ice cream and the debt is cleared. Glad I could help.
Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

