Odd behavior when Command Buttons are present.

RaudelJr
2StarLounger
Posts: 136
Joined: 17 Apr 2017, 19:16

Odd behavior when Command Buttons are present.

Post by RaudelJr »

I have created a step by step as suggested by Cindy Meister at https://stackoverflow.com/questions/559 ... 2#55965262" onclick="window.open(this.href);return false;

I posted this as a new thread as it merits a topic of it's own.
Some talk about this topic is at https://www.eileenslounge.com/viewtopic ... 26&t=32374" onclick="window.open(this.href);return false; towards the end.

Open a Word Document

Create a and enter the following code:

Code: Select all

Sub UpdateOptions()
    Dim bProtected As Boolean
    'Unprotect the file
    If ActiveDocument.ProtectionType <> wdNoProtection Then
        bProtected = True
        ActiveDocument.Unprotect Password:=""
    End If


    Select Case ActiveDocument.FormFields("Bookmark0").Result
        Case "Bookmark1"
            ActiveDocument.Bookmarks("Bookmark1").Select
            SendKeys "%{down}"  'Displays choices in drop-down field
        Case "Bookmark2"
            ActiveDocument.Bookmarks("Bookmark2").Select
            SendKeys "%{down}"  'Displays choices in drop-down field
        Case "Bookmark3"
            ActiveDocument.Bookmarks("Bookmark3").Select
            SendKeys "%{down}"  'Displays choices in drop-down field
    End Select
    If bProtected = True Then
        ActiveDocument.Protect _
            Type:=wdAllowOnlyFormFields, _
            NoReset:=True, _
            Password:=""
    End If
End Sub

Back to Word Document

Type Bookmark0
Insert a Legacy Drop down Form Field
List: Bookmark1, Bookmark2, Bookmark3
Bookmark: Bookmark0
Run Macro on Exit: UpdateOptions

Enter
Enter
Type Bookmark1
Insert a second Legacy Drop down Form Field
List: 1, 2, 3.
Bookmark: Bookmark1

Enter
Enter
Type Bookmark 2
Insert a third Legacy Drop down Form Field
List: 1, 2, 3.
Bookmark: Bookmark2

Enter
Enter
Type Bookmark3
Insert a fourth Legacy Drop down Form Field
List: 1, 2, 3.
Bookmark: Bookmark3

Your document should look like this at this point:

Bookmark0[dropdown]

Bookmark1[dropdown]

Bookmark2[dropdown]

Bookmark3[dropdown]

Save document as a Macro Enabled document.

Lock document
NoButton NoConflict.docm

Testing:
- Change the first drowpdown options only from the available listed options (Bookmark1, Bookmark2, Bookmark3)
- Every time you change your selection you will be directed to the corresponding Bookmark Dropdown Form Field.
- Should be working as expected.


---------------------------------------------------------------------------------------------

Next, Button conflict

Unlock document
Insert a Button at the end of the document below Bookmark3
[Button]

Your document should look like the same as above but with a button now:

Bookmark0[dropdown]

Bookmark1[dropdown]

Bookmark2[dropdown]

Bookmark3[dropdown]

[Button]

Lock document
YesButton YesConflict.docm
Testing Button conflict:
- Change Bookmak0 selection from (Bookmark1, Bookmark2, Bookmark3)
- Every time you change your selection you will NOT be directed to the corresponding Bookmark Dropdown Form Field.
- Every time you change your selection you will be directed to a field after the intended corresponding Bookmark Dropdown Form Field.
- Macro is not working as expected with the presence of a Button.
- Unlock document, delete the button, lock document, it will be working fine again.

---------------------------------------------------------------------

Thank you for any help in advance solving this Button conflict.

Raudel
You do not have the required permissions to view the files attached to this post.

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Odd behavior when Command Buttons are present.

Post by macropod »

In addition to the stackoverflow cross-post, cross-posted at:
http://www.msofficeforums.com/word-vba/ ... esent.html" onclick="window.open(this.href);return false;
http://www.vbaexpress.com/forum/showthr ... re-present" onclick="window.open(this.href);return false;
Paul Edstein
[Fmr MS MVP - Word]

RaudelJr
2StarLounger
Posts: 136
Joined: 17 Apr 2017, 19:16

Re: Odd behavior when Command Buttons are present.

Post by RaudelJr »

Hi there macropod.

Been typing until late night with one eye closed and one eye open.

At a given point I missed including the other links again.

Just trying to figure out these odd behavior.

Thank you for bringing this to my attention again.

Any help is appreciated.

Raudel