Results 1 to 4 of 4

Thread: Populating combo box with results from SP

  1. #1

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721

    Populating combo box with results from SP

    Hi

    Please can anyone help I need to populate a combo box with the results returned froma stord Proc.

    My code so FAR is
    [vbcode]
    Public Function ContactDetails()

    Dim rsSet As ADODB.Recordset
    Dim ObjCmd As Command

    Set rsSet = New ADODB.Recordset

    With rsSet
    .CursorLocation = adUseClient
    .LockType = adLockOptimistic
    .CursorType = adOpenDynamic
    End With

    Set ObjCmd = New Command
    With ObjCmd
    .ActiveConnection = gBass
    .CommandType = adCmdStoredProc
    .CommandText = "upSel_ContactDetails"
    .Parameters.Append .CreateParameter("@AcNo", adVarChar, adParamInput,
    40, AC_NO)
    End With

    Set rsSet = ObjCmd.Execute
    CmboContact.RowSourceType = "value list"
    CmboContact.RowSource = BuildComboList(rsSet)

    End Function

    Private Function BuildComboList(rs As ADODB.Recordset)
    Dim OutStr As String

    Do While Not rs.EOF()
    OutStr = OutStr & """" & rs!AC_NO & """" & ";" & """" & rs!Contact_char &
    """" & ";"
    rs.MoveNext
    Loop
    CmboContact = OutStr

    End Function
    [/vbcode]

    Thanks for your help!!!
    ** HOLLY **

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Populating combo box with results from SP

    Would this work for you?
    Code:
    Private Function BuildComboList(rs As ADODB.Recordset, cbo As Combobox)
    Dim OutStr As String
    
        Do While Not rs.EOF()
            OutStr = OutStr & Chr(34) & rs!AC_NO & Chr(34) & ";" & Chr(34) & rs!Contact_char & Chr(34) & ";"
            cbo.AddItem OutStr
            rs.MoveNext
        Loop
    
    End Function
    
    'usage:
    
    BuildComboList rsSet, CmboContact

  3. #3

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721

    Re: Populating combo box with results from SP

    Sorry it did not work..has anyone any other ideas???
    ** HOLLY **

  4. #4

Posting Permissions

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



Click Here to Expand Forum to Full Width