Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cascading Dropdowns help needed in Word 2003

Status
Not open for further replies.

eendly

Technical User
May 4, 2010
5
US
HI,

I'm trying to format a form with cascading dropdowns. Here are fields:
State
Property name
Property address

The objective is to have the user select the state they are in and then next field will be populated with only the properties in that state. when they select the property only the addresses for that property will show up.

I keep getting an error - "Object required"

I'm not sre what i'm missing, here is the code:

Sub StateList()
If ActiveDocument.FormFields("state").DropDown.Value = 0 Then
ActiveDocument.FormFields("legal").DropDown.ListEntries.Clear
Exit Sub
End If
Select Case ActiveDocument.FormFields("state").Result
Case "NJ"
With ActiveDocument.FormFields("legal").DropDown.ListEntries
.Clear
.Add "legal name"
.Add "legal name 2"
End With
Case "MA"
With ActiveDocument.FormFields("legal").DropDown.ListEntries
.Clear
.Add "legal name 3"
End With
Case "NY"
With ActiveDocument.FormFields("legal").DropDown.ListEntries
.Clear
.Add ""
.Add ""
.Add ""
End With
Case "VA"
With ActiveDocument.FormFields("legal").DropDown.ListEntries
.Clear
.Add ""
.Add ""
.Add ""
End With
End Select
End Sub
Sub LegalList()
If ActiveDocument.FormFields("legal").DropDown.Value = 0 Then
ActiveDocument.FormFields("address").DropDown.ListEntries.Clear
Exit Sub
End If

Select Case ActiveDocument.FormFields("legal").Result
Case "legal name"
With ActiveDocument.FormFields("address").DropDown.ListEntries
.Clear
.Add "55 Main St, USA"
End With
End Select
Select Case ActiveDocument.FormFields("legal").Result
Case "legal name 2"
With ActiveDocument.FormFields("address").DropDown.ListEntries
.Clear
.Add "8200 Main St, USA"
End With
End Select
Select Case ActiveDocument.FormFields("legal").Result
Case "legal name 3"
With ActiveDocument.FormFields("address").DropDown.ListEntries
.Clear
.Add "100 Main St, USA"
.Add "1310 Main St, USA"
End With
End Select
 
I think it's pointing me to the sub lelaglist statement.
 


There is no "sub lelaglist "

There is, however a Sub LegalList.

However, you have NOT included ALL the code. Maybe THAT'S your problem???

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Also, there is something funny with the code you posted. Why have you put THREE uses of Select Case for the same thing?
Code:
[highlight]Select Case ActiveDocument.FormFields("legal").Result[/highlight]
    Case "legal name"
        With ActiveDocument.FormFields("address").DropDown.ListEntries
        .Clear
        .Add "55  Main St, USA"
        End With
End Select
[highlight]Select Case ActiveDocument.FormFields("legal").Result[/highlight]
    Case "legal name 2"
        With ActiveDocument.FormFields("address").DropDown.ListEntries
        .Clear
        .Add "8200  Main St, USA"
        End With
End Select
[highlight]Select Case ActiveDocument.FormFields("legal").Result[/highlight]
    Case "legal name 3"
        With ActiveDocument.FormFields("address").DropDown.ListEntries
        .Clear
        .Add "100  Main St, USA"
        .Add "1310 Main St, USA"
        End With
    End Select
Surely this is supposed to be:
Code:
Select Case ActiveDocument.FormFields("legal").Result
    Case "legal name"
        With ActiveDocument.FormFields("address").DropDown.ListEntries
        .Clear
        .Add "55  Main St, USA"
        End With
    Case "legal name 2"
        With ActiveDocument.FormFields("address").DropDown.ListEntries
        .Clear
        .Add "8200  Main St, USA"
        End With
    Case "legal name 3"
        With ActiveDocument.FormFields("address").DropDown.ListEntries
        .Clear
        .Add "100  Main St, USA"
        .Add "1310 Main St, USA"
        End With
End Select
If you are getting an object required error, then you have some instruction that requires an object and you are not explicitly giving it. It does not happen randomly.

Are you using Option Explicit? This helps to avoid some of these, as it requires you to explicitly declare your variables and objects. It avoids spelling/syntax error - one of the most common erasons for the Object Required error.


Gerry
 



and to piggyback...
Code:
With ActiveDocument.FormFields("address").DropDown.ListEntries
    Select Case ActiveDocument.FormFields("legal").Result
        Case "legal name"
            .Clear
            .Add "55  Main St, USA"
        Case "legal name 2"
            .Clear
            .Add "8200  Main St, USA"
        Case "legal name 3"
            .Clear
            .Add "100  Main St, USA"
            .Add "1310 Main St, USA"
    End Select
End With

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
it was a spelling error, but i will try the piggyback code, it would be much easier.

I still have another layer of dropdowns to add with names.

Thanks
 


Your error - "Object required" was a spelling error?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


and as Gerry stated, Use Option Explicit to catch these kinds of errors before you run your code.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
If it was a spelling error, then - again - I strong strongly strongly encourage you to start using Option Explicit, like right now.

Gerry
 
I'm not familiar with 'Option Explicit'. can some one please explain and give sample code.
 
For existing code modules:

Type Option Explicit as the first line.

For any new modules you create:

In the Visual Basic Editor, click Tools > Options and then check Require Variable Declaration, and then press OK.

Now any new modules will automatically have Option Explicit.

Setting it in Tools > Options does not add it to existing code modules.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top