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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dependent Drop-Down lists in Word 2003

Status
Not open for further replies.

dldev

Programmer
Sep 4, 2007
33
0
0
US
Hello,

I've been looking at different approaches for creating a dependent drop-down list (or text box), but have been unable to come up with a solution that works. In some cases there will be only one value for a value chosen in a drop-down, in other cases there may be more than one. In the cases where there is more than one a drop-down is fine, but in the cases where there is only one a text box (or perhaps a disabled drop-down) would suffice. Or, could this simply be done with Field Codes or Bookmarks? In any case, any help or point in the right direction, examples, anything would be greatly appreciated. Seems like it's a lot easier in Excel to create dependent drop-down lists than Word, but unfortunately, this has to be done in Word.

Thanks,
Dennis
 





Hi,

Use ActiveX Data Objects to query your data. The first combo selection, becomes a criteria value for the second query to populate the second combobox.

Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
Hi Skip,

Any chance I could get a brief example, or a good resource? I did some searching but was unable to find very much information. Sorry, newbie Word automatino programmer here.

Thanks,
Dennis
 


Code:
Sub MG_List(sCC As String) As Variant
    Dim sConn As String, sSQL As String, sServer As String
    Dim rst As ADODB.Recordset, cnn As ADODB.Connection
    
    Set cnn = New ADODB.Connection
    
    sServer = "DWPROD"
    cnn.Open "Driver={Microsoft ODBC for Oracle};" & _
               "Server=" & sServer & ";" & _
               "Uid=;" & _
               "Pwd="
    
    Set rst = New ADODB.Recordset
    
    sSQL = "SELECT DISTINCT MACH_GRP "
    sSQL = sSQL & "FROM FRH.PSK02233 "
    sSQL = sSQL & "Where CC='" & sCC & "' "
    
    rst.Open sSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText
                          
    rst.MoveFirst

    YourComboBox.Clear

    If IsNull(rst(0)) Then
      do while not rst.eof
        YourComboBox.AddItem  rst(0)
        rst.movenext
      loop
    End If

    rst.Close
    cnn.Close
    
    Set rst = Nothing
    Set cnn = Nothing
End Sub


Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top