Link to home
Start Free TrialLog in
Avatar of vgunas1
vgunas1

asked on

Creating a Form in MS Word

Hi,

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!

Thanks!
Avatar of Anne Troy
Anne Troy
Flag of United States of America image

I just explained how to add two fields at this question:

https://www.experts-exchange.com/questions/20791359/embedding-formulas-in-a-Word-document.html

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. :)
ASKER CERTIFIED SOLUTION
Avatar of Quetzal
Quetzal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ehout
ehout

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


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 controls....it's different and make take a little orientation, but in the end, it's much more powerful (imho)
Hi,

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
ActiveDocument.FormFields("tv1").Select
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 ;-)
Avatar of vgunas1

ASKER

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!:)
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.
Avatar of vgunas1

ASKER

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!

Thanks.
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.
Avatar of vgunas1

ASKER

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!:)