AutoFill Text from Dropdown

D

Dax Arroway

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 couldn't find anything.)

Thanks so much in advance!
--Dax
 
D

Doug Robbins - Word MVP

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
 
D

Dax Arroway

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
<Level 2 C text>, and so on and so forth. Does anyone have something that
could do this? Seems simple enough. I've actually figure out how to do this
with Excel but I don't 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???
 
D

Doug Robbins - Word MVP

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
 
D

Dax Arroway

Hi Doug et al,
Thank you and yes that's perfect. The cells will be filled with different
information across the table so I'll use the latter example and cut and paste
the text into the macro. I'm also using "Level 1" through "Level 5" as the
dropdown choices for each cell A1:A5, however, they're unique. So there's
differenty "types" of questions associated with the levels. In other words I
need different titles so I get different results. I'm 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'm 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 doesn't seem
to work. I'm 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'm using Word03 on an WinXP machine if that helps.

Thanks again,
--Dax
 
D

Doug Robbins - Word MVP

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.

Dax Arroway said:
Hi Doug et al,
Thank you and yes that's perfect. The cells will be filled with different
information across the table so I'll use the latter example and cut and
paste
the text into the macro. I'm also using "Level 1" through "Level 5" as
the
dropdown choices for each cell A1:A5, however, they're unique. So there's
differenty "types" of questions associated with the levels. In other
words I
need different titles so I get different results. I'm 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'm 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 doesn't
seem
to work. I'm 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'm using Word03 on an WinXP machine if that helps.

Thanks again,
--Dax
 
D

Dax Arroway

Website's currently down but I think I'm 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'm 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'm stuck. From what I know of Macros and how to call and run
them I'm doing everything right. What am I missing?

When the website comes back up I'll reveiw the remedial Macro stuff but I'm
wondering if its something else maybe???

--Dax
 
D

Doug Robbins - Word MVP

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.

Dax Arroway said:
Website's currently down but I think I'm 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'm 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'm stuck. From what I know of Macros and how to call and
run
them I'm doing everything right. What am I missing?

When the website comes back up I'll reveiw the remedial Macro stuff but
I'm
wondering if its something else maybe???

--Dax
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top