![]() |
|
#1
|
|||
|
|||
![]()
Hi,
I have created a form with form fields and I require that when ever I select a different option from the AON Type field that everything Orange change Colour EG Safety Notice- Yellow Sop Update - Green Advisory Bulletin - Dark Grey AON - Training Update - Pink I really have no idea on how to start this and would appreciate some help / advice. |
#2
|
||||
|
||||
![]()
Instructionalhelp:
Kindly - 1. Don't post the same question multiple times; 2. Resurrect ancient threads on unrelated topics; and 3. Hijack existing threads on unrelated topics. I have deleted one post to which 1 & 2 apply and moved the post to which 1 & 3 apply to its own thread. As for the problem itself, see the formfield demonstration in the attachment at: https://www.msofficeforums.com/word-...html#post47254
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thank you for your advice and assistance.
I have tried this but still seem to be having no luck. Kind regards |
#4
|
||||
|
||||
![]()
Your attachment is a .docx file. Files in the .docx format cannot contain macros, so it is impossible for me to see what steps you've taken to implement the solution I pointed you to.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Apologies for that I attached incorrect file. Here we go. I have been trying for days to get it going so I have so many files saved now
![]() |
#6
|
||||
|
||||
![]()
There is no code in your latest attachment, either, so it is impossible for me to see what steps you've taken to implement the solution I pointed you to.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
I have just checked the file I sent to you and I can see the macro and the code when I open it and go to the developer tab and macros.
Please see a copy and paste of what I see. End Sub Option Explicit Dim i As Long Private Sub Document_Open() ActiveDocument.Bookmarks("ColourDropDown").Range.S elect Call Index End Sub Sub Index() i = Replace(Selection.FormFields(1).Range.Bookmarks(1) .Name, "ColourDropDown", "") End Sub Sub ColorDropDown() Dim sText As String, oFld As FormField With ActiveDocument Set oFld = .FormFields("Dropdown" & i) sText = oFld.Result If .ProtectionType <> wdNoProtection Then .Unprotect Password:="" With oFld.Range Select Case sText Case Is = "SOP UPDATE" 'green .Font.Color = wdColorBrightGreen .Shading.BackgroundPatternColor = wdColorBrightGreen Case Is = "SAFETY NOTICE" 'yellow .Font.Color = wdColorYellow .Shading.BackgroundPatternColor = wdColorYellow Case Is = "TRAINING UPDATE" 'pink .Font.Color = wdColorRed .Shading.BackgroundPatternColor = wdColorRed Case Is = "ADVISORY BULLETIN" 'grey .Font.Color = wdColorRed .Shading.BackgroundPatternColor = wdColorRed End Select End With .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="" End With End Sub |
#8
|
||||
|
||||
![]() Quote:
PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
Thank you for this.
Please find attached file and hopefully macro is attached to document and not template. Kind regards |
#10
|
||||
|
||||
![]()
Your code doesn't make much sense to me.
There's an obvious error with 'End Sub' appearing before 'Option Explicit'. Then you have a Document_Open macro that selects the 'ColourDropDown' bookmark and then calls an 'Index' macro that tries to populate a variable 'i' with whatever appears in the corresponding formfield's internal bookmark after 'ColourDropDown'. A coding error there means the code falls over that that point. If it worked, 'i' would always be 0, since the formfield's name is the same as the 'ColourDropDown' bookmark itself. So what is the point of the 'i' variable? If the above worked, you would then have your formfield call the 'ColorDropDown' macro, whose code looks for a formfield named '"DropDown" & i' which, if anything, would always evaluate to 'DropDown0'. But no such formfield exists - the dropdown formfield's name is only ever 'ColourDropDown' and no other formfield with a name like '"DropDown" & i' exists in the document. Finally, even if you resolve all of the above, your code would set the Dropdown selection's font and background to the same colour, effectively making the text invisible.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
![]()
Sadly I am still having no luck but I may be totally misunderstanding what you are saying.
Should it be this hard? |
#12
|
||||
|
||||
![]()
It really isn't hard if you don't try to be unnecessarily creative and take care with what you're doing. See attached. Compare my code to yours...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Drop Downs | Suray1911 | Excel | 1 | 09-29-2015 10:31 PM |
![]() |
MicrosoftNovice2015 | Excel | 1 | 09-15-2015 02:16 PM |
![]() |
rbd50 | Mail Merge | 3 | 03-31-2015 09:52 PM |
![]() |
Andrew H | Word VBA | 15 | 11-16-2012 08:34 AM |
![]() |
mhays | Excel | 6 | 01-16-2012 09:29 AM |