PDA

View Full Version : Odd behavior when Command Buttons are present.



RaudelJr
05-02-2019, 08:58 PM
Also posted in msofficeforums

Hi,

I have a situation where word has an odd behavior when Command Buttons are present.

I'm attaching two Word Template files, one with buttons and one without.

The file with No Buttons was the original file.
I added the buttons to the file to copy content between bookmarks using a Button and also to reset the form by clearing all fields using a Button.

But it seems like adding the Buttons caused a sort of a glitch.

If you look at the VBA code, the UpdateUptions() Macro is supposed to select the corresponding bookmarked dropdowns and display the selections.

It does it correctly when the form has no Buttons. But as soon as the Buttons are added, at the end of the UpdateOptions() macro, Word seems to move to a field that is after the intended dropdown.

The file attached with No Buttons, has the UpdateOptions() macro working as expected, though if you were to edit this file and add a command button, and do nothing more, it will begin having the problem.


And the file attached With Buttons, has the UpdateOptions() macro affected by the presence of the buttons.

I would like to add, that the issue is easier to observe if you change the Word settings to view Hidden Text (Options>Display>Select Hidden Text

Not sure how to resolve the weird behavior.

Thanks in advance for your help.

Raudel

24179

macropod
05-02-2019, 09:40 PM
Cross-posted at: http://www.msofficeforums.com/word-vba/42422-odd-behavior-when-command-buttons-present.html
Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3

RaudelJr
05-02-2019, 09:46 PM
Cross-posted at:
Please read VBA Express' policy on Cross-Posting in Rule 3:

Hi Macropod,
I did mention at the very top that I posted at msofficeforums.
Initially I entered the complete URL, but while attempting to submit the post, it gave me an error stating I had invalid URL, so I only entered the forum name.
I cant even quote your last reply without removing the URLs.

Please see original post.

I didn't want to cross post. But I have this document due tomorrow, and I've spend hours researching.

I might end up having to do a workaround.

Any help is appreciated.

RaudelJr
05-03-2019, 12:51 AM
I have created a step by step as suggested by Cindy Meister at stackoverflow forum.


I hope you are successful at creating a Macro enabled document that has a working Macro first, but then stops working with the insertion of a Button. Instructions below.


--------------------
Open a Word Document


Create a and enter the following code:



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


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

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

24182

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




Now insert a button a test again.

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

Testing issue below
- 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.

24181


--------------------------------------------------------------------------
Thank you in advance for your help with this Button problem.

Raudel

gmayor
05-03-2019, 04:01 AM
See your other thread.

RaudelJr
05-03-2019, 07:26 AM
See your other thread.

Hi there gmayor,

I've 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.

Not trying to break the rules. It was just late night and was updating posts and code. Very tired.

Any help is appreciated. But I understand if some took offense, but I did mention cross posting, sorry I missed going back and updating the links again. I'm not a child, but I feel reprimended as one. I'm sure someone can reason I was trying to follow the cross posting rules. I would have gone back this morning with a fresh start and made sure it was all properly reported as I do understand the importance of the rule.

If anyone knows how to solve the issue with this thread topic, I would really appreciate the help.


Raudel

EDIT >> My other thread got closed. I'm reviewing your reply in that thread. Thank you gmayor.

RaudelJr
05-03-2019, 07:52 AM
Hi gmayor,

The Department I'm in, isn't using Content Controls at this time.

Their entire templates repository are built with Legacy Form Fields, moving to Content Controls won't happen in the near future.

So I'm trying to work out this specific issue because I'm trying to facilitate some of the steps to the user/worker.

Since the issue causes the selection to move forward one, I might end up needing to select a field prior so that when it skips forward, due to the odd behavior, it will land on the intended location.

Thank you for your help.

Raudel

macropod
05-03-2019, 02:25 PM
Also cross-posted at: https://www.eileenslounge.com/viewtopic.php?f=26&t=32411

RaudelJr
05-03-2019, 07:27 PM
Hi Admins,

It was a long week. I would appreciate the thread being closed. I haven't resolved the issue, but due to the issues highlighted, I'm sure no further replies will be posted and with the thread closed I would stop checking back in hopes of a reply. At this point I didn't meet my deadline, so I submitted the file with an ugly workaround (I'll keep researching and will clean it up if I find a solution).

I'll come back another time with other questions when I feel less pressured for time.

Thank you all, the growing information in this forum and the help provided is very useful.

Raudel