Solved

Creating a Form in MS Word

Posted on 2003-11-07
21
1,157 Views
Last Modified: 2010-08-05
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!
0
Comment
Question by:vgunas1
  • 8
  • 8
  • 3
  • +1
21 Comments
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9707797
I just explained how to add two fields at this question:

http://www.experts-exchange.com/Applications/MS_Office/Word/Q_20791359.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. :)
0
 
LVL 11

Accepted Solution

by:
Quetzal earned 250 total points
ID: 9709780
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.
0
 
LVL 3

Expert Comment

by:ehout
ID: 9714544
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


0
 
LVL 3

Expert Comment

by:ehout
ID: 9714556
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
0
 
LVL 11

Expert Comment

by:Quetzal
ID: 9714658
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
0
 
LVL 11

Expert Comment

by:Quetzal
ID: 9714711
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)
0
 
LVL 3

Expert Comment

by:ehout
ID: 9714727
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
0
 
LVL 3

Expert Comment

by:ehout
ID: 9714747
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
0
 
LVL 11

Expert Comment

by:Quetzal
ID: 9714764
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.
0
 
LVL 11

Expert Comment

by:Quetzal
ID: 9714803
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.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:Quetzal
ID: 9714813
pardon the editing....english really is my first and only language....but you might not be able to tell by some of my posts :)
0
 
LVL 3

Expert Comment

by:ehout
ID: 9714825
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
0
 
LVL 3

Expert Comment

by:ehout
ID: 9714856
The best way in here might be to have it fired onexit
0
 
LVL 3

Expert Comment

by:ehout
ID: 9714867
Hmmm... speaking of editing, I wish we would be able to edit our comments afterwards. In some situations it would be helpful
0
 
LVL 11

Expert Comment

by:Quetzal
ID: 9714878
I agree that if the forms control approach is taken, it is best to fire on exit.
0
 
LVL 3

Expert Comment

by:ehout
ID: 9714885
Well, at least vgunas1 has something to think about now ;-)
0
 

Author Comment

by:vgunas1
ID: 9715277
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!:)
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 9715338
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.
0
 

Author Comment

by:vgunas1
ID: 9715383
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.
0
 
LVL 11

Expert Comment

by:Quetzal
ID: 9716575
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.
0
 

Author Comment

by:vgunas1
ID: 9716626
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!:)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you ever had the experience that you had to follow 10 steps over and over again every time when you need to nicely forward an important email to your manager? Fear no more! With the help of the Quick Steps feature in Outlook 2010, your old chor…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now