Results 1 to 8 of 8

Thread: Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed

    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?

    Code:
    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
    Last edited by silvrwood; Jun 6th, 2005 at 12:43 PM.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed

    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)

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Re: Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed

    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?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed

    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

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Re: Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed

    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Resolved Re: Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed

    Consequently, it looks like bookmarks really weren't the way to go, but perhaps docvariables are. I will be posting more under that topic.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed

    just put in a form field REF, it can get its value from a vaiable or from a textbox or whatever

    pete

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Resolved Re: Dropdowns in Word Run Code First Time Selection Made but Not if Selection Changed

    I ended up using docVariables, which work much more reliably for me, tied into userforms.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width