Field Codes

G

Guest

I have a form to design, in Word, that needs to give the following
functionality. I would need in a column, a choice of say, 4 items. (I can
do this by means of a dropdown box), and then I would need to have another
column whose choice would be dependant on what was chosen in the first
column. To elaborate, if I was to have the choice of 3 makes of car, BMW
(available colours, Blue, green and Black) , Merc (yellow, red and orange)
and Jag (white and pink), these choices would only be available, depending on
the choice of car chosen first. Any help would be appreciated. Thanks
 
D

Doug Robbins - Word MVP

Run the following macro on exit from the first dropdown (assigned the
bookmark name of "Make" in this code) and it will add the necessary items to
the second dropdown (assigned the bookmark name of "Colour")

Dim Make As Long, i As Long

Make = ActiveDocument.FormFields("Make").DropDown.Value
With ActiveDocument.FormFields("Colour").DropDown.ListEntries
For i = .Count To 1 Step -1
.Item(i).Delete
Next i
If Make = "1" Then
.Add "Blue"
.Add "Green"
.Add "Black"
ElseIf Make = "2" Then
.Add "Yellow"
.Add "Red"
.Add "Orange"
Else
.Add "White"
.Add "Pink"
End If
End With

--
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
 
G

Guest

Doug,

Thank you very much. I have copied this macro, but when I run it, I get a
compile error "invalid outside procedure" and it highlights the ("Make") part
in the second line of code. I have built the form, using the Make and Type
dropdowns) although I will rename them later to suit the specific needs of my
form) so I can understand how this works, I have not changed any of the
coding. Please excuse me if it is a very simple mistake - I have not used
macros before although I would rate myself as an intermediate PC user who is
very intuitive!

I am working in the USA for the MoD, so please don't think I have not
answered you posts earlier - time difference! Thank you for you continued
assistance

Charlie
 
D

Doug Robbins - Word MVP

You need to insert that code inside a Sub [macroname]() - End Sub
construction and set the macro with the name that you assign in place of
[macroname] to be run on exit from the Make formfield.

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


--
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
 
G

Guest

pompeyboyUSA said:
I have a form to design, in Word, that needs to give the following
functionality. I would need in a column, a choice of say, 4 items. (I can
do this by means of a dropdown box), and then I would need to have another
column whose choice would be dependant on what was chosen in the first
column. To elaborate, if I was to have the choice of 3 makes of car, BMW
(available colours, Blue, green and Black) , Merc (yellow, red and orange)
and Jag (white and pink), these choices would only be available, depending on
the choice of car chosen first. Any help would be appreciated. Thanks

Doug,
Understood now, I was having problems understanding what went where, it
works perfectly now - thank you very much

Charlie
 
G

Guest

Doug Robbins - Word MVP said:
You need to insert that code inside a Sub [macroname]() - End Sub
construction and set the macro with the name that you assign in place of
[macroname] to be run on exit from the Make formfield.

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


--
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

pompeyboyUSA said:
Doug,

Thank you very much. I have copied this macro, but when I run it, I get a
compile error "invalid outside procedure" and it highlights the ("Make")
part
in the second line of code. I have built the form, using the Make and
Type
dropdowns) although I will rename them later to suit the specific needs of
my
form) so I can understand how this works, I have not changed any of the
coding. Please excuse me if it is a very simple mistake - I have not used
macros before although I would rate myself as an intermediate PC user who
is
very intuitive!

I am working in the USA for the MoD, so please don't think I have not
answered you posts earlier - time difference! Thank you for you continued
assistance

Charlie


Doug,

Works pefectly now, I was having problems understanding what went where, all
works fine - thank you very much

Charlie
 

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