Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    I have a word doc with various form fields inserted. On one field, there is a list of values for a drop-down and in another field, there is a Number associated with each program name. What I'd like to do is have the Program Number field automatically update itself depending on the selection of the Program Name field. I have created a Select Case macro but haven't had much success referencing the Program Name Field value to set the variable for the Select Case code. How do you reference the value of a Word field (or, as it calls itself, a Bookmark) in code?

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    To get the vaule of a FormField, you need to use:

    Debug.Print ThisDocument.FormFields("DropDown1").Result

    In this case DropDown1 is the bookmark name of the DropDown form field.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Star Lounger
    Join Date
    Jun 2002
    Posts
    98
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    Here's an idea. Use the "Run macro on Exit" property of the first drop-down field to update the second field:

    <pre>Sub DropDown1_Exit()

    Select Case ActiveDocument.FormFields("Dropdown1").Result
    Case "Peter"
    n = 10
    Case "Paul"
    n = 20
    Case "Mary"
    n = "30"
    End Select

    ActiveDocument.FormFields("Dropdown2").Result = n

    End Sub
    </pre>


    Unfortunately, the user has to actually EXIT the field before the updating occurs.
    In a real UserForm (not a form field in a doc) you could make this update "real-time" which users will find more intuitive.
    __________________________________________________ ____
    <img src=/S/nun.gif border=0 alt=nun width=20 height=20> Sister Dory
    Our Lady of Perpetual Help, Holstein Falls, Wisconsin, USA

  4. #4
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    that looks about right. from what i can gather, Word Form fields apply macros either on Exit or on Enter & applying the change to On Exit for the Program Names field (which will be tabbed in before Program Number) is the better choice. Of course, even better would be to not have an 'updateable' Program Number field because, after going thru all the trouble to assign a value to it, the User could tab in, erase or change the assigned value...in which case you'd have to re-run the same macros as on on Exit to Program Number field. A little goofy, but I wouldn't be suprised if Word's form field handling is primitive. There's no radio buttons provided in the Forms toolbar, for instance. Also, not sure if you can control tab order or disable a field. Well, it ain't Access we're talking about, but Word. I've asked my client to look over the automation & let me know if drop-downs are even something he wants. With the drop-downs, you prevent multiple selections for a category, but the form no longer looks like the passive paper form so it may be more confusing for the user. don't know...I *like* drop-downs, but that doesn't mean the client will!

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    Thanks for the reply, esp. the referenced thread discussion. I might need to use {REF} in some fields as info is repeated on the second page of the form. As for using VB to create better forms in Word, good suggestion but for this project I think I can get by using what Word makes available.

    One thing that is actually something of a positive using Word's native form toolset: you get a very good sense of how the form would look in HTML/asp! The native form handling with these technologies is even more primitive, as you don't have onExit events. For example, you can select a Program Name in the initial form and have the system find/display the associated Program Number on the preview/submit page. (You could probably use javascript for event-driven web pages, but I avoid javascript for critical functionality as there are browser compatibility issues with javascript.) But you can see how a web page might look after creating a form in Word (except of course Radio Buttons, which don't exist in Word forms but do in HTML).

  6. #6
    Star Lounger
    Join Date
    Jun 2002
    Posts
    98
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    (Edited by HansV to activate link to post - see <!help=19>Help 19<!/help>)

    Good points, Steve. I just posted a summary of how I like to do "form fill-in" templates in another thread: <post#=255721>post 255721</post#>

    I insert a UserForm in the VB editor and use it to allow proper data entry with all the bells & whistles then stuff the results in fields & bookmarks, etc.
    Form Fields just don't cut it after you've used real forms. UserForms are practically the same thing you're used to in MS Access forms.
    __________________________________________________ ____
    <img src=/S/nun.gif border=0 alt=nun width=20 height=20> Sister Dory
    Our Lady of Perpetual Help, Holstein Falls, Wisconsin, USA

  7. #7
    New Lounger
    Join Date
    Feb 2003
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    Finally got around to installing the suggested code. works perfectly! also, if you disenable the 'target' form field you can't tab into it and change any results. very nice.

  8. #8
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    Hi Steve

    I think I am correct in assuming that Dory was actually referring to Word's own VBA, rather than VB, when she mentioned the "VB editor". VBA is, of course, integral to MS Office, not an "extra" application like VB is.

    Alan

  9. #9
    Star Lounger
    Join Date
    Jun 2002
    Posts
    98
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    Right you are, Alan. In Word's Tools...Macros... menu, it is called the "Visual Basic Editor". I wouldn't send anyone over to Visual Basic 6.0 for a simple trick like this! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    When you know how to do little tricks in the "VB Editor" of Word, Excel & Access you hardly ever have to bother with Visual Basic stand-alone application development. I hope more people try Visual Basic for Applications (or macros or embedded VB or whatever you want to call it) and aren't scared off by the idea of "programming". It's great stuff. (The night security guard at my client's office was reading a C++ manual the other night. Lookin' for a career change. I recommended he start with VBA macros in Excel or Word before tackling that challenge. Got to have some easy wins to keep scaling that learning curve.) OK...this is getting WAY off topic. Apology to moderator. <img src=/S/doh.gif border=0 alt=doh width=15 height=15>
    __________________________________________________ ____
    <img src=/S/nun.gif border=0 alt=nun width=20 height=20> Sister Dory
    Our Lady of Perpetual Help, Holstein Falls, Wisconsin, USA

  10. #10
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing a Bookmark (field) in Macro (Win 2KPro, Office2KPro)

    that's what i assumed when she suggested using VB for creating custom forms. I've never actually tried using VB 6+ etc. but have done a lot of stuff using VB for Office in various apps. However, when I stated I'd stick with the native form elements provided by Word, I was referring to what you get in the View | Toolbars... Forms toolbar. You have to use the VB Editor in Word to hook up actions on these Word forms (which seem to be a collection of custom field codes) at any rate.

Posting Permissions

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