combo box...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas1111
    New Member
    • Feb 2008
    • 122

    combo box...

    I have connected combo box to database and the first content of the column is displayed.. I want to display all the contents of the column in combo box .. How can i do that ?
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    post the code how you have connected to database.

    Comment

    • vikas1111
      New Member
      • Feb 2008
      • 122

      #3
      Originally posted by debasisdas
      post the code how you have connected to database.
      Hi this is the code which i have written...

      Option Explicit
      Dim c As New ADODB.Connectio n
      Dim cm As ADODB.Command
      Dim rs As New ADODB.Recordset

      Private Sub Form_Load()
      Dim cs As String
      c.Open ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=d:/_______.mdb;Per sist Security Info=false")

      rs.Open "select * from _______", c, adOpenDynamic
      Me.Combo1.Text = rs(2)
      Do Until rs.EOF = True
      rs.MoveNext
      Loop
      End Sub

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        To Display all the Available Names, use a "DataCombo" or "DatListBox " and set these Properties..:

        With DC1
        Set .RowSource = RS
        .ListField =MyFieldName
        .BoundColumn = MyFieldName
        .Refresh
        End With

        REgards
        Veena

        Comment

        • QVeen72
          Recognized Expert Top Contributor
          • Oct 2006
          • 1445

          #5
          Hi,

          You need to add the Items in Loop..

          [code=vb]
          rs.Open "select * from _______", c, adOpenDynamic
          Do Until rs.EOF = True
          Me.Combo1AddIte m rs(2)
          rs.MoveNext
          Loop

          [/code]

          Regards
          Veena

          Comment

          • vikas1111
            New Member
            • Feb 2008
            • 122

            #6
            Originally posted by QVeen72
            Hi,

            You need to add the Items in Loop..

            [code=vb]
            rs.Open "select * from _______", c, adOpenDynamic
            Do Until rs.EOF = True
            Me.Combo1AddIte m rs(2)
            rs.MoveNext
            Loop

            [/code]

            Regards
            Veena

            Hi
            Me.Combo1. AddItem rs(2) now its working .. tks

            Comment

            • Ali Rizwan
              Banned
              Contributor
              • Aug 2007
              • 931

              #7
              Hi,

              After connecting your database use this code.

              [CODE=vb]REC.MoveFirst

              Do While Not REC.EOF
              Combo1.Additem (REC.Fields(0))
              REC.MoveNext
              loop[/CODE]

              Regards
              >> ALI <<
              Last edited by debasisdas; Mar 6 '08, 12:03 PM. Reason: added code=vb tags

              Comment

              Working...