Windows XP
(1)
Excel
(1)
Word
(1)
Selection.FormFields
(1)
VBA
(1)
MacrosVBA
(1)
Range.FormFields
(1)
FAQs
(1)

AutoFill Text from Dropdown

Asked By Dax Arroway
08-Jan-10 02:56 PM
I have a 5x5 table in which the first column has drop downs with choices
Level 1 through Level 5.  The columns have descriptive text in them which
should change depending upon the users choices in the dropdowns.  Is there a
way of doing this?

For instance, if someone opened this form and selected Level II from the
dropdown menu, the cells across the row would fill with predetermined text
that matched descriptions for Level II.  If they changed it to Level III, the
descriptions would follow, and so on and so forth.

Does anyone know how to do this or know where a webpost is or a webpage
which describes the process.  (And excuse me if this is all ready discussed.
I searched but could not find anything.)

Thanks so much in advance!
--Dax
--
I would give my left hand to be ambidextrous!

Here is one way of doing it.

Doug Robbins - Word MVP replied to Dax Arroway
09-Jan-10 10:48 PM
Here is one way of doing it.

Assuming that you wanted the same result in all of the cells 2 through 5 of
a row, you would run a macro containing the following code on exit from the
dropdown formfield in each cell of the first column:

Dim ddresult As String
ddresult = Selection.FormFields(1).result
Select Case ddresult
Case "Level 1"
For i = 2 To 5
Selection.Rows(1).Cells(i).Range.FormFields(1).result = "Result
for Level 1"
Next i
Case "Level 2"
For i = 2 To 5
Selection.Rows(1).Cells(i).Range.FormFields(1).result = "Result
for Level 2"
Next i
Case "Level 3"
For i = 2 To 5
Selection.Rows(1).Cells(i).Range.FormFields(1).result = "Result
for Level 3"
Next i
Case "Level 4"
For i = 2 To 5
Selection.Rows(1).Cells(i).Range.FormFields(1).result = "Result
for Level 4"
Next i
Case Else
For i = 2 To 5
Selection.Rows(1).Cells(i).Range.FormFields(1).result = "Result
for Level 5"
Next i
End Select

If you want something different in each cell in the row, then in place of
the constructions like

For i = 2 To 5
Selection.Rows(1).Cells(i).Range.FormFields(1).result = "Result
for Level 1"
Next i

you are going to need

Selection.Rows(1).Cells(2).Range.FormFields(1).result = "Result for
Level 1 in Column 2"
Selection.Rows(1).Cells(3).Range.FormFields(1).result = "Result for
Level 1 in Column 3"
Selection.Rows(1).Cells(4).Range.FormFields(1).result = "Result for
Level 1 in Column 4"
Selection.Rows(1).Cells(5).Range.FormFields(1).result = "Result for
Level 1 in Column 5"

If you do not want the user to be able to edit the result in columns 2
through 5, you can uncheck the Fill-in enabled box for the formfields in
those cells.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Sort of like an IF, THEN statement.

Dax Arroway replied to Dax Arroway
10-Jan-10 10:05 PM
Sort of like an IF, THEN statement.  IF cell A1 has Level 1 selected from the
dropdown, then B1 is <Level 1 B text>, C1 is <Level 1 C text>, D1 is <Level 1
D text>.  Or if A1 is Level 2 selected, then B1 is <Level 2 B text>, C1 is
could do this?  Seems simple enough.  I have actually figure out how to do this
with Excel but I do not want an inserted excel document into my Word document.
I'd rather it only be a Word document with a Word Table.  I can also do this
with HTML but again, I'd prefer this only be a Word doc.  Anyone???
--
I would give my left hand to be ambidextrous!

See my response to your original post.--Hope this helps.

Doug Robbins - Word MVP replied to Dax Arroway
12-Jan-10 05:59 AM
See my response to your original post.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Hi Doug et al,Thank you and yes that is perfect.
Dax Arroway replied to Doug Robbins - Word MVP
12-Jan-10 03:30 PM
Hi Doug et al,
Thank you and yes that is perfect.  The cells will be filled with different
information across the table so I will use the latter example and cut and paste
the text into the macro.  I am also using "Level 1" through "Level 5" as the
dropdown choices for each cell A1:A5, however, they are unique.  So there is
differenty "types" of questions associated with the levels.  In other words I
need different titles so I get different results.  I am guessing I could
simply put Case "A1Level 1", Case "A2Level 1" through out the code to obtain
these?  Or is there a simpler way?

The other part that is eluding me is where this should go, how I should put
it into the document, and how to get the macro to run from the dropdown.

I am guessing I create a new macro, give it a name, which then opens the VBA
Editor and I insert the code into the box.  Is that right?  It does not seem
to work.  I am obviously missing an important fundimental part.  Should I be
inserting bookmarks into the cells or something?

Can someone describe the steps or is there an idiot's guide to macros
someplace?  I am using Word03 on an WinXP machine if that helps.

Thanks again,
--Dax
-------------------------------------
I would give my left hand to be ambidextrous!
See the article "What do I do with macros sent to me by other newsgroupreaders
Doug Robbins - Word MVP replied to Dax Arroway
13-Jan-10 01:47 AM
See the article "What do I do with macros sent to me by other newsgroup
readers to help me out???? at:
http://www.word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

In the properties dialog box for the form field, you need to select that
macro to be run on exit from the field.

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
Website's currently down but I think I am doing this right.
Dax Arroway replied to Doug Robbins - Word MVP
13-Jan-10 01:33 PM
Website's currently down but I think I am doing this right.  Sorry for the
remedialness of this post but just to make sure please let me walk through my
steps.

Create word document and save.
Go to Tools\Macros\Macros, enter PCC for Macro Name, leave All active
templ...click Create.
VBA opens.  Cut and paste code into macro.  Close VBA editor.
Back in Word, Insert Table, 5 cells by 5 cells.
In first cell (A1) create dropdown menu giving 5 entries Level 1 throug
Level 5
Select PCC in dropdown of Macros to run on Exit.  Leave dropdown enabled and
Calculate on exit unchecked.  Bookmark default is Dropdown1, leave that.
Go to next cell down (A2) follow same procedue as A1, leave default bookmark
as Dropdown2.
Continue through A5.  Lock document.  Save.

At this point I am thinking I should be done and it should work.  I drop down
the first dropdown and select a level, tab to next dropdown, and I get a MSVB
Run-time error '5941': The requested member of the collection does not exist.

Clicking Debug opens the VBA Editor which shows this highlighted code under
the selection I'd chosen in the dropdown.  This code is:
Selection.Rows(1).Cells(i).Range.FormFields(1).Result = "Result for Level 3"

At this point I am stuck.  From what I know of Macros and how to call and run
them I am doing everything right.  What am I missing?

When the website comes back up I will reveiw the remedial Macro stuff but I am
wondering if its something else maybe???

--Dax

--
I would give my left hand to be ambidextrous!
The macro was written on the assumption that the formfields in columns
Doug Robbins - Word MVP replied to Dax Arroway
17-Jan-10 05:30 PM
The macro was written on the assumption that the formfields in columns 2
through 5 would be textinput type formfields

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
Post Question To EggHeadCafe