Results 1 to 11 of 11
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Defining form fields programmatically (WinNT4, Word97)

    Sorry, folks, I'm having problems with form fields again! I checked my other recent thread on similar lines but my poor brain can't see how to use the code given to do what I want this time.

    I've worked out how to insert a form field check box in the table I'm working on, but I need to set its size, and can I work out how to do that?! I can't find anything that will tell me what properties a check box has (what they're called in vba, that is) and I can't work out how to select it in order to apply the properties.

    <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining form fields programmatically (WinNT4, Word97)

    Here is some code that creates a check box and sets a few properties:

    With Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormCheckBox)
    .Name = "Check1" ' Bookmark name
    .CheckBox.AutoSize = False ' Don't autosize
    .CheckBox.Size = 12 ' Set size explicitly (in points)
    .CheckBox.Default = True ' Check box is on by default
    End With

    A good way to find out about the available properties is to look up the FormField and CheckBox objects in Word VBA Help. Or activate the Object Browser (F2 in the VBE), and type FormField in the search box.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Defining form fields programmatically (WinNT4, Word97)

    Ah, now I see where it's going. Many thanks, Hans <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    Could I just ask, what would you put in the help box to get it to tell you what properties are available to a check box? I couldn't track it down earlier!
    Beryl M


  4. #4
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Defining form fields programmatically (WinNT4, Word97)

    > what would you put in the help box to get it to tell you what properties are available to a check box

    Start as Hans said, "activate the Object Browser (F2 in the VBE), and type FormField in the search box." Then click on CheckBox (or any other property) and press F1.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Defining form fields programmatically (WinNT4, Word97)

    Thanks for that, Sam, but when I followed the instructions the (extraordinarily helpful) window that came up just said:

    "Returns a CheckBox object that represents a check box form field. Read-only.
    Remarks
    If the CheckBox property is applied to a FormField object that isn't a check box form field, the property won't fail, but the Valid property for the returned object will be False."

    How do I infer what properties (eg autosize, size and default, to use the ones Hans put in as examples) are available, please? <img src=/S/grovel.gif border=0 alt=grovel width=31 height=23>
    Beryl M


  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Defining form fields programmatically (WinNT4, Word97)

    PS The bit about "a good way to start ..." in Hans' post he must have added after posting the original, because it wasn't in the email I received notifiying me of his reply!
    Beryl M


  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining form fields programmatically (WinNT4, Word97)

    You got to the help page for the CheckBox property. In the sentence "Returns a CheckBox object that ...", the word CheckBox should be a hyperlink to the help page for the CheckBox object that is much more informative, with some examples, and a link to the popup list of properties at the top.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining form fields programmatically (WinNT4, Word97)

    Sorry about that. I edited my reply immediately after posting it, and didn't mark it as changed.

  9. #9
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Defining form fields programmatically (WinNT4, Word97)

    'Sno problem, but would you marking it as edited have caused an email to be sent to me saying so? I don't remember ever seeing one ...
    Beryl M


  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Defining form fields programmatically (WinNT4, Word97)

    Dunno, I don't use e-mail notifications myself...

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Defining form fields programmatically (WinNT4, Word97)

    No, you only get the notification for the original post, not for edits.
    Charlotte

Posting Permissions

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