Creating a Form in MS Word


I am trying to create a form in MS Word. I am using the form toolbar to put in drop down lists and text boxes. I am a beginner at this and hence I don’t know if it would better to do it this way or to use the visual basic toolbar to create the form.

The form has the following;

Dropdown box with values: Communication, Technical skills, Learning Orientation

The user has to choose of the values from the drop down box. As soon as he chooses the value a corresponding text has to appear in a text box which is situated below the drop down.

For eg: if the user chooses Communication the text “ measures the communication” should appear in the text box. If he chooses Technical skills the text “technical skills including programming languages” should appear in the text box and so on.

The form has a couple of other drop down lists with values 1, 2,3 and 4.

There is another text below the two dropdown boxes. After the user chooses the values in the two drop down boxes the sum of these values should be displayed in the text box.

The problem is that I have no idea of how to program this since I am a beginner. Also I am not allowed to use any tables or command buttons in the form.

Can anyone please let me know the various detailed steps that I have to follow inorder to create such a form. It would be greatly appreciated!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anne TroyEast Coast ManagerCommented:
I just explained how to add two fields at this question:

I'm sorry, I don't know how to do the IF part.
If someone else does, you should just give them all the points. :)
To do what you want, it would be better to use the control toolbox rather than the forms toolbar.  This allows you to create class module event procedures that fire when you make changes in the various controls.

Let's do a simple example:

1. Open a blank document.

2. Choose View->Toolsbars and select Control Toolbox

3. Find the combobox tool, click on it and a combo box will appear (size it if you want).

4. Right-click the combobox and choose View Code.  You should be in the vba editor on a procedure called ComboBox1_Change.  Make it look like the following:

Private Sub ComboBox1_Change()
Select Case ComboBox1.ListIndex
  Case 0
    TextBox1.Text = "measures the communication"
  Case 1
    TextBox1.Text = "technical skills including programming languages"
  Case 1
    TextBox1.Text = "learning methods"
End Select

5. in the vba code window, in the upper right, click to pulldown menu (which should show "Change") and select "GotFocus".  Make the ComboBox1_GotFocus procedure look like the following:

Private Sub ComboBox1_GotFocus()
If (ComboBox1.ListCount = 0) Then
  ComboBox1.AddItem "Communication"
  ComboBox1.AddItem "Technical skills"
  ComboBox1.AddItem "Learning Orientation"
End If
End Sub

6. Before you leave the class module add the following statement as the very first statement of the module:
Option Explicit

7. Go back to the document, click off the combobox (to anywhere else on the document).  Find the textbox tool, click on it and a text box will appear.

8. Click the Design mode icon on the Control Toolbar.  The textbox should not now be selected.

9. Select Tools->Protect Document.  Select Forms and for this example, don't put in a password.

10. Click on the combobox and select an item.  The corresponding text will appear in the text box below.

Is this kind of what you are looking for?  If so, we can talk further about the elements that went into doing it.  I've picked specific ways to do things for this example, but as usual there are many ways to accomplish the same thing, each with  pros and cons.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hmm Quetzal, This is quite a massive solution for a VBA newbie. Also, when this form needs to be printed, real VB controls don't look very nice. I'ld rather stick to the forms toolbar and use those controls, though the principle of Quetzal's comment still can be used.

Over here I created a document in which I made 1 listobx (list1) and 1 textbox (tv1).
I filled the listbox with your values.

Then I wrote the following macrocode, which is almost like the one in Quetzal's comment.

Sub FillTextField()
  Select Case ActiveDocument.FormFields("list1").Result
    Case "Technical skills"
      ActiveDocument.FormFields("tv1").Result = "technical skills including programming languages"
    Case "Communication"
      ActiveDocument.FormFields("tv1").Result = "measures the communication"
    Case "learning orientation"
      ActiveDocument.FormFields("tv1").Result = "learning methods"
  End Select
End Sub

The main difference is the use of formfield instead of VB objects.

Now in de properties of the combo formfield, select the Macro FillTextField to be run when chosing an option.

That should be it for the first part.

The second part of your question actually can be solved in pretty much the same way.

I created 4 combos (of course again from the formfields bar) and populated them with the values 1 to 4. I named the combos NrField1, NrField2, NrField3 and Nrfield4
And I placed another textbox, namend tv2.

Now put a second Macro in your code, as follows.

Sub GetNumbers()
Dim oField
Dim bCounter As Byte
  bCounter = 0
  For Each oField In ActiveDocument.FormFields
    If Left(oField.Name, 7) = "NrField" Then
      bCounter = bCounter + oField.Result
    End If
  Next oField
  ActiveDocument.FormFields("tv2").Result = bCounter
End Sub

And again, go to the properties of the four combo's and select this macro to be run when a user chooses a value in the combo.

This should do the trick.

What happens is that each time a value is chosen in 1 of the combos, all combos are counted and the result is placed in tv1.

Notice that this function as I wrote it here relies on the naming of the combos, so be accurate in this.

Hope this helps.

Kind regards

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Sorry,, small error.

In the sentence
"What happens is that each time a value is chosen in 1 of the combos, all combos are counted and the result is placed in tv1"

Tv1 of course must be tv2

Kind regards
ehout, how did you get the macro fire autmatically when the dropdown changes? I think your only option is to specify macros on enter and exit...somewhat clunky to me.  The VBA controls will fire on change.

BTW if you don't like the way the VBA controls prints make the following changes and they will look, act, and print like the forms controls:

set control property SpecialEffect to frmSpecialEffectFlat
set control property ShowDropButtonWhen to frmShowDropButtonWhenFocus
btw, I don't see a real big difference between forms with macros and vba's different and make take a little orientation, but in the end, it's much more powerful (imho)

Hmmm... You are right about the entrymacro. Problem is that I use a dutch version, and the description in the properties screen is actually the translation for "choose" instead of entry. A bit tricky.

However, adding the statement
after  the "end select" line will help.

Kind regards
I agree with you that VB objects give more power and a greator control. However, documents with form objects behave like... well, like forms.

And as vgunas1 states he is a beginner, I think using the standard form things with only a little VBA might be more appropriate for the level of knowledge.

Kind regards
I don't think that adding the select will help.  The problem with the forms control is that you must enter or exit the field in order to fire the macro.  Simply changing the dropdown entry does neither.
I think the key to the solution is whether the various changes that must occur (like the textbox) should as the user makes choices or whether it is acceptable to wait until the user moves out of or into a field.

Doing "a little" VB for macros is lot like being a little pregnant.  There's a certain about of knowledge you have to use to get that far and the few extra steps to get the power of the controls (seems to me) to be worth it.
pardon the editing....english really is my first and only language....but you might not be able to tell by some of my posts :)
Yeah, I can agree on that.

BTW, you're right about that last addition (select).  It makes no sense, so he'ld better skip that line. I was tricked by the focus lying on another form field.

However, I'll see if I can get that onchange effect done.

In the meanwhile, for my solution indeed the onenter and onexit effects are the ones he'll have to deal with.

Kind regards
The best way in here might be to have it fired onexit
Hmmm... speaking of editing, I wish we would be able to edit our comments afterwards. In some situations it would be helpful
I agree that if the forms control approach is taken, it is best to fire on exit.
Well, at least vgunas1 has something to think about now ;-)
vgunas1Author Commented:
Hi Quetzal,

I think I like your solution better. By using ehout's solution I couldnt get the macros to fire correctly and change the fields. Using yours was easier and the text in the text box changed once I selected the option in the combo box.

I also looked at your code for adding two fields. It works for adding up values in two text boxes. Now that I am using a control toolbar to change text I would like to use the control toolbar and create two other drop down boxes and one more text box. I would like to add the values in the two drop down boxes and display them in the text box. Can you tell me how I can go about doing that.

Thanks a lot!:)
Anne TroyEast Coast ManagerCommented:
vgunas1: That's really another question and should be asked separately. It sounds like Quetzal has already answered your first question and, for that, you should award points.
vgunas1Author Commented:
Hi Dreamboat,

I will definitely award quetzal the points but if you look at my original question in the beginning it had this component too!!! So I dont think I am wrong in looking for an answer for both components!

vgunas1, I will be back to help u with last part of your question, but prb not until tonite...busy right at the moment....not ignoring you.
vgunas1Author Commented:
Hi Quetzal,

Thanks for replying. I solved the second part of the question. It was very similar to your other solution. I tried it and figured it out.

Thanks anyways!:)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.