Populating Combo with Ado Recordset 
Author Message
 Populating Combo with Ado Recordset

For a non bound combo ...............

PopulateCombo "CountryList", cboCountry(0), "txtDesc", "IdCountry"

Sub PopulateCombo(StoredProc As String, Combo As ComboBox, ListField As
String, BoundField As String)

    Set Cmd = New ADODB.Command
        Cmd.ActiveConnection = Conn
        Cmd.CommandText = "" & StoredProc & ""
        Cmd.CommandType = adCmdStoredProc

    Set RecSet = Cmd.Execute

    Combo.Clear

    Do Until RecSet.EOF = True

        With Combo
            .AddItem RecSet.Fields(ListField)
            .ItemData(Combo.NewIndex) = RecSet.Fields(BoundField)
        End With

    RecSet.MoveNext
    Loop

    RecSet.Close
    Set RecSet = Nothing

End Sub

Note this is for SqlServer ....

For ordinary recordest just replace "CountryList" with sql ....

i.e

"SELECT IdCountry, Country FROM tblCountries"

Regards

VOrtex


Quote:
> Hi,
> I'm loading a form which populates the combo every time.
> the content of the combo may/may not varry everytime.
> Can anyone suggest me the efficient way to populate the combo with
> ADO Recordset?
> Your help in this will be highly appreciated.

> Thank you.
> suresh P



Wed, 15 Oct 2003 06:01:30 GMT  
 Populating Combo with Ado Recordset
Hi,

well and thanks for your help.
But i'm more interested in the type of cursor location and recordsets's
dbopentype properties.
Can you help me in that?
thank you.

Suresh P

Quote:
-----Original Message-----

For a non bound combo ...............

PopulateCombo "CountryList", cboCountry(0), "txtDesc", "IdCountry"

Sub PopulateCombo(StoredProc As String, Combo As ComboBox, ListField As
String, BoundField As String)

    Set Cmd = New ADODB.Command
        Cmd.ActiveConnection = Conn
        Cmd.CommandText = "" & StoredProc & ""
        Cmd.CommandType = adCmdStoredProc

    Set RecSet = Cmd.Execute

    Combo.Clear

    Do Until RecSet.EOF = True

        With Combo
            .AddItem RecSet.Fields(ListField)
            .ItemData(Combo.NewIndex) = RecSet.Fields(BoundField)
        End With

    RecSet.MoveNext
    Loop

    RecSet.Close
    Set RecSet = Nothing

End Sub

Note this is for SqlServer ....

For ordinary recordest just replace "CountryList" with sql ....

i.e

"SELECT IdCountry, Country FROM tblCountries"

Regards

VOrtex



> Hi,
> I'm loading a form which populates the combo every time.
> the content of the combo may/may not varry everytime.
> Can anyone suggest me the efficient way to populate the combo with
> ADO Recordset?
> Your help in this will be highly appreciated.

> Thank you.
> suresh P

.



Wed, 15 Oct 2003 06:41:45 GMT  
 Populating Combo with Ado Recordset
If its non bound then use a forwardonly,readonly

If its bound then

Static and readonly

Perhaps you should tell me exactly what you are trying to do !!

Regards

VOrtex


Quote:
> Hi,

> well and thanks for your help.
> But i'm more interested in the type of cursor location and recordsets's
> dbopentype properties.
> Can you help me in that?
> thank you.

> Suresh P

> -----Original Message-----
> For a non bound combo ...............

> PopulateCombo "CountryList", cboCountry(0), "txtDesc", "IdCountry"

> Sub PopulateCombo(StoredProc As String, Combo As ComboBox, ListField As
> String, BoundField As String)

>     Set Cmd = New ADODB.Command
>         Cmd.ActiveConnection = Conn
>         Cmd.CommandText = "" & StoredProc & ""
>         Cmd.CommandType = adCmdStoredProc

>     Set RecSet = Cmd.Execute

>     Combo.Clear

>     Do Until RecSet.EOF = True

>         With Combo
>             .AddItem RecSet.Fields(ListField)
>             .ItemData(Combo.NewIndex) = RecSet.Fields(BoundField)
>         End With

>     RecSet.MoveNext
>     Loop

>     RecSet.Close
>     Set RecSet = Nothing

> End Sub

> Note this is for SqlServer ....

> For ordinary recordest just replace "CountryList" with sql ....

> i.e

> "SELECT IdCountry, Country FROM tblCountries"

> Regards

> VOrtex



> > Hi,
> > I'm loading a form which populates the combo every time.
> > the content of the combo may/may not varry everytime.
> > Can anyone suggest me the efficient way to populate the combo with
> > ADO Recordset?
> > Your help in this will be highly appreciated.

> > Thank you.
> > suresh P

> .



Sat, 18 Oct 2003 09:33:30 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Populating Combo with ADO Recordset

2. populating combo with ADO recordset

3. Populating Combo box with recordset data

4. Populate a data combo with a recordset

5. ado,and populating a combo box

6. How to populate Combo box with ADO/RS

7. Populate a combo box with ADO code

8. Populating a TDBGrid with an ADO Recordset

9. How to Populate an ADO RecordSet

10. Populating TreeView with flat ADO Recordset

11. Populate Sub-report from ADO Recordset

12. ADO populating DataGrid from Recordset(data retrieved from stored procedure using 3 parameters)

 

 
Powered by phpBB® Forum Software