Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Sep 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Drop down form fields (Word 2000)

    I have a series of templates that contains numerous text form fields and can also contain 2 to 4 drop down form fields. Each of the form fields is in a separate table cell. The drop down form fields have a set number of choices of which the first one is "Select Title". I am trying the write one macro that can be used by all the drop down form fields to check that a selection has been made. I have part of the macro working in that if the text ="select Title" then a message box is shown and the focus returned to the drop down box again. I am using run macro on exit to trigger the macro. This works when I place the form field name in the code.

    My question - is there a way the determine the name of the drop down from field that has been exited and pass it to the macro so that the one macro will work for all drop down boxes.
    My code so far:

    Sub dropDown()
    If ActiveDocument.FormFields("SelectTitle2").Result = "Select Title" Then
    MsgBox "You must select a position title"
    Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="GoBack"
    End If
    End Sub

    Sub GoBack()
    ActiveDocument.FormFields("SelectTitle2").Range.Se lect
    End Sub

    Thanks

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Drop down form fields (Word 2000)

    If there isn't a way to ascertain which FormField is "active" (e.g., using the Selection, which might work, I haven't tested it), you could create a small Exit macro for each one, in which you call the main macro with the parameter of which control it should analyze.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Drop down form fields (Word 2000)

    If the formfield has an associated bookmark then Selection.Bookmarks(1).Name seems to give the correct control in an Exit macro.

    StuartR

  4. #4
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Drop down form fields (Word 2000)

    This works only for Checkbox and Dropdown, not for Textinput. ( Added: Oops, it's the other way around; works for TextInput, not for Checkbox and Dropdown... <img src=/S/doh.gif border=0 alt=doh width=15 height=15> ) That's why I use this Function that I found on the net somewhere (mvp.org?)


    Public Function GetFFName() As String

    On Error Resume Next

    GetFFName = "ERROR"
    If Documents.Count < 1 Then Exit Function
    With Selection
    If .FormFields.Count = 1 Then
    'Checkbox or Dropdown
    GetFFName = .FormFields (1).Name
    ElseIf .FormFields.Count = 0 And .Bookmarks.Count > 0 Then
    'Textinput
    GetFFName = .Bookmarks(.Bookmarks.Count).Name
    End If
    End With
    End Function

  5. #5
    Star Lounger
    Join Date
    Sep 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Drop down form fields (Word 2000)

    Thanks Stuart

    The line of code works. I thought I tried that code last night without success, shouldn't try programming late at night when I should be asleep.

    just added a line so the first two lines now read

    Name = Selection.Bookmarks(1).Name
    If ActiveDocument.FormFields(Name).Result = "Select Title" Then

    Both drop down form fields work correctly using the one on exit macro.

    Cheers
    Kosey

  6. #6
    Star Lounger
    Join Date
    Sep 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Drop down form fields (Word 2000)

    Thanks also to Ischer and Jan, for their suggestions.

    Regards

Posting Permissions

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