Consulting

Results 1 to 8 of 8

Thread: Solved: Help with VBA and forms

  1. #1

    Solved: Help with VBA and forms

    The goal: I’m trying to automate Word so that when a particular choice is made on a form dropdown list it changes what the current choice is on a different dropdown list.

    Example

    List 1 (Bookmark name: Member) has the following choices
    Bob
    Chuck
    Mark

    List 2 (Bookmark name: Number)
    1
    2
    3

    So if I select Bob from List 1, List 2 automatically sets itself to 1. When trying to do this, I am getting an error that prohibits this because Word is in a protected state, but if I turn protection off the drop down lists don’t work anyway.

    Thanks!

  2. #2
    VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Can you post the code that you have so far?

  3. #3
    Actually, I just got it working. My basic mistake was using ActiveDocument.Bookmarks instead of ActiveDocument.FormFields.

    Thank you for responding though!

  4. #4
    VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Would you like to post your code anyway? It may prove helpful to someone else in the future.

  5. #5
    Sure!

    Select Case ActiveDocument.FormFields("Member").Result
    Case "Bob"
    ActiveDocument.FormFields("Number").Result = "1"
    Case "Chuck"
    ActiveDocument.FormFields("Number").Result = "2"
    Case "Mark"
    ActiveDocument.FormFields("Number").Result = "3"
    End Select

    Simple as that...and it only took me hours to figure out.

  6. #6
    VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    You could also try this:

    [vba]
    With ActiveDocument.FormFields("Number")
    Select Case ActiveDocument.FormFields("Member").Result
    Case "Bob": .Result = "1"
    Case "Chuck": .Result = "2"
    Case "Mark": .Result = "3"
    End Select
    End With
    [/vba]

  7. #7
    Oh, that's much cleaner. Thanks!

  8. #8
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Nice use of With statement geekgirlau.

    cvernon: "My basic mistake was using ActiveDocument.Bookmarks instead of ActiveDocument.FormFields. "

    Unfortunately - and I have no idea how this got going (although the Word MVP site has some responsibility I think) - this is very commonly used. Personally I think it is a bad idea to use one object (Bookmarks), when you actually mean another (Formfields).

Posting Permissions

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