PDA

Click to See Complete Forum and Search --> : Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed


silvrwood
Jun 6th, 2005, 12:36 PM
Can someone tell me why
1. This code only changes the bookmark text the first time the selection is made but not if the user changes the selection thereafter?
2. My document is set up as section protected for the first section only (to enable the dropdowns and checkboxes), but I have to directly tell it in the code to unprotect the doc in order for the macro to not error with the indication that the macro could not be run because the doc was protected?

Sub StatusM()

' If the value of the dropdown is "single" then the areas
' in the document that this should populate will also include
' the text " person"


Dim vStatSelect As Integer
Dim vStat As String

vStatSelect = ActiveDocument.FormFields("Status").DropDown.Value

Select Case vStatSelect

Case 2
vStat = "single person"

Case 3
vStat = "widow"

Case 4
vStat = "widower"

End Select

If ActiveDocument.ProtectionType <> wdNoProtection Then

ActiveDocument.Unprotect

End If



Selection.GoTo What:=wdGoToBookmark, Name:="StatusP"
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.InsertAfter vStat
ActiveDocument.Bookmarks.Add Range:=Selection.Range, _
Name:="StatusP"

Selection.GoTo What:=wdGoToBookmark, Name:="Status"

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True


End Sub

Ecniv
Jun 7th, 2005, 03:30 AM
1. This code only changes the bookmark text the first time the selection is made but not if the user changes the selection thereafter?

This suggests that the event you are calling this from is not running (on_Change? on_Click?)


2. My document is set up as section protected for the first section only (to enable the dropdowns and checkboxes), but I have to directly tell it in the code to unprotect the doc in order for the macro to not error with the indication that the macro could not be run because the doc was protected?

Um not sure. is the book mark with in the protected area?
Possibly all the bookmarks are protected as well.
The Delete may be removing the book mark then you recreate it? (guessing)

silvrwood
Jun 9th, 2005, 10:49 AM
This suggests that the event you are calling this from is not running (on_Change? on_Click?)
That's what it seems like to me, but what I can't figure out is why. This is not a combo box or list in a user form, but a standard drop down form field for use in Word forms with the option to run a macro upon exit checked. Are the form fields only set up to run the exit macro once, or do I need to run something on entering the field as well?

Um not sure. is the book mark with in the protected area?
Possibly all the bookmarks are protected as well.
The Delete may be removing the book mark then you recreate it? (guessing)
The bookmark is not in the protected area. Do bookmarks have a protection property?
I do think the code overwrites the bookmark then reinserts it. This was the only code I could find that successfully placed the text to insert inside the bookmark rather than before or after it so that it would allow it to be overwritten. Do you have any other code that would work better for this?

westconn1
Jun 9th, 2005, 11:10 AM
i don't know about bookmarks being protected, but you could put in a ref field and then just set the reference that will work on a protected forms document

is the bookmark still there after the first time the macro is run, or has it been replaced by the text inserted?

pete

silvrwood
Jun 10th, 2005, 04:32 PM
I have scrapped this method as being inefficient from a production standpoint. However, there was another dropdown in the form that, rather than populating a bookmark, prompted for another answer if the selection was yes. This one did not seem to initiate the click method either when the selection was changed. It would prompt for the name the first time but if I changed the selection to no then back to yes it would not prompt again.

silvrwood
Jun 13th, 2005, 12:52 PM
Consequently, it looks like bookmarks really weren't the way to go, but perhaps docvariables are. I will be posting more under that topic.

westconn1
Jun 13th, 2005, 07:39 PM
just put in a form field REF, it can get its value from a vaiable or from a textbox or whatever

pete

silvrwood
Jul 13th, 2005, 10:49 AM
I ended up using docVariables, which work much more reliably for me, tied into userforms.