Consulting

Results 1 to 9 of 9

Thread: Conditional drop down list 5941

  1. #1
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    5
    Location

    Conditional drop down list 5941

    First let me say I'm a word noob and I'm probably doing something really dumb here. I'm trying to add conditional drop down lists to a document. To be able to select a car make and then get a list of models. I named the lists MakeDD and ModelDD

    Sub Dealerbos()
    If ActiveDocument.FormFields("MakeDD").DropDown.Value = 0 Then
    ActiveDocument.FormFields("ModelDD").DropDown.ListEntries.Clear
    Exit Sub
    End If
    Select Case ActiveDocument.FormFields("MakeDD").Result
    Case "Acura"
    With ActiveDocument.FormFields("ModelDD").DropDown.ListEntries
    .Clear
    .Add "MDX"
    .Add "RDX"
    .Add "RL"
    .Add "TL"
    .Add "TSX"
    .Add "ZDX"
    End With

    Code is not mine. Found a guide about doing this and modified the above code. It throws a runtime error 5941 on the first line.

    If ActiveDocument.FormFields("MakeDD").DropDown.Value = 0 Then

    Like it's not reading the MakeDD drop down box. What's the deal here?

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    See: http://gregmaxey.mvps.org/Linked_DropDown_Fields.htm

    [VBA]Sub Dealerbos()
    Dim oLEs As ListEntries
    Set oLEs = ActiveDocument.FormFields("ModelDD").DropDown.ListEntries
    Select Case ActiveDocument.FormFields("MakeDD").Result
    Case "Acura"
    With oLEs
    .Clear
    .Add "MDX"
    .Add "RDX"
    .Add "RL"
    .Add "TL"
    .Add "TSX"
    .Add "ZDX"
    End With
    Case "Accord"

    Case "Ridge Line"

    Case Else
    oLEs.Clear
    End Select
    End Sub
    [/VBA]
    Last edited by gmaxey; 09-02-2011 at 06:43 AM.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    5
    Location
    Syntax error on the first line.

    Sub Dealerbos()

    What's going on?

  4. #4
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    5
    Location
    Nevermind, silly syntax error on my part. Well I'm back to runtime error 5941. On:

    Set oLEs = ActiveDocument.FormFields("ModelDD").DropDown.ListEntries

    Same line as with the previous code. What's the deal?

    Also I'm not sure about this option to run on exit. I thought it was removed from office 2007 and on. As there is no properties option when right clicking on a form field.
    Last edited by Verbos83; 09-02-2011 at 07:34 PM.

  5. #5
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Are you absolutely certain that you actually have a dropdown formfield in the document bookmarked "ModelDD"
    Greg

    Visit my website: http://gregmaxey.com

  6. #6
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    5
    Location
    Again, sneaking suspicion I'm doing something terribly obvious here. I opened properties on the drop down and set the title and tag to MakeDD and ModelDD on the involved drop downs. I see no reference to the default bookmarks. I think I'm missing something here. I've also set bookmarks under insert, but they don't seem to have the same meaning as the examples on your site. There are no generic DropDown1, Text1 bookmarks prefilled in there.

  7. #7
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location

    Attachment

    Try the attached.
    Attached Files Attached Files
    Greg

    Visit my website: http://gregmaxey.com

  8. #8
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    5
    Location
    Thanks for your patience Greg. I was using the drop down list content control, not the drop down list under legacy.

  9. #9
    VBAX Regular
    Joined
    Sep 2011
    Posts
    12
    Location
    Gmaxey
    Good work .......... Good example

Posting Permissions

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