PDA

View Full Version : Conditional drop down list 5941



Verbos83
09-02-2011, 06:11 AM
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?

gmaxey
09-02-2011, 06:26 AM
See: http://gregmaxey.mvps.org/Linked_DropDown_Fields.htm

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

Verbos83
09-02-2011, 04:34 PM
Syntax error on the first line.

Sub Dealerbos()

What's going on?

Verbos83
09-02-2011, 07:20 PM
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.

gmaxey
09-02-2011, 07:34 PM
Are you absolutely certain that you actually have a dropdown formfield in the document bookmarked "ModelDD"

Verbos83
09-02-2011, 07:53 PM
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.

gmaxey
09-03-2011, 01:55 AM
Try the attached.

Verbos83
09-03-2011, 07:33 AM
Thanks for your patience Greg. I was using the drop down list content control, not the drop down list under legacy.

firas
09-25-2011, 05:06 AM
Gmaxey:clap2:
Good work .......... Good example