Results 1 to 13 of 13
  1. #1
    Lounger
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ComboBox - ADODC - DB (VB6)

    I am going to link a combo box to one column of DB via ADO and wish the combox to show up the list of all the rows of that column ( string names).
    I used properties window (DataSource - ado name and DataField - the column name) to link the combobox with the ado arrow box. It however only shows one name not all the list of the names. If you click the arrows on ado box, combo box changes the name one by one but this is not what I want. I want the combo box show up the name list from DB and user can select the name from the combo list or input the name that match the list.

    Can anyone tell me how to make the list show up in the combo box via adodc (either by code or by changes on propertie)?

    Thanks,

    David

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ComboBox - ADODC - DB (VB6)

    If by clicking the "arrows on the ado box" you mean what I think you mean, you're actually moving through the records and so you see the value bound to that field in each record. If you want to see all the names, click on the combobox arrow to drop it down.
    Charlotte

  3. #3
    Lounger
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ComboBox - ADODC - DB (VB6)

    Sorry Charlotte, I had to click the combobox arrow to see if the dropdown field contains the list or not. I couldnt conclude there was no list by just seeing that single top row or input/showup field in combo box.

    I can see the single record one by one in that single row showup field of the combobox (yes it means moving through the records) when click the adodc arrow(s) but have a BLANK dropdown field when click the combobox arrow. So who can help me to setup the list in the dropdown field? I failed to find some way to AddItem in a loop (suppose there are n items, unknown in design stage) in form _load code.

    David

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ComboBox - ADODC - DB (VB6)

    I'm not sure I follow you. What style did you apply to the combobox? Have you set the ListField property? If you set the DataField property, that binds the control to the underlying recordset, which means if there is a value for the field in the recordset, you should see it in the combobox rather than a blank. What is the rowsource for your combobox? Did you bind it to your datacontrol or to another datasource for the RowSource property?
    Charlotte

  5. #5
    Lounger
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ComboBox - ADODC - DB (VB6)

    My combobox links to adodc thru DataSource property and I have only one adodc component. In the adodc's RecordSource property, I have a very simple SQL statement "select movie_name from tblA" where "movie_name" is the column/field name I want to show as a list in the combobox. As it can show single record of the column, the link with adodc and DB should be no problem. There must be something to do with the combobox. DataField property of the combobox is set "movie_name", which actually is the only option to choose as my SQL selects only one column. Style property is set "Dropdown Combo" as other two options are either not suitable or not working.

    I dont know what RowSource and ListField properties you mentioned are. There are no such properties in combobox property window (at least in VB6). I checked msdn that the properties seem related to DataCombo, which I have no idea how to use it and I guess it is used for linking more tables. In my case, it is a very simple link, one datasource, one table to link, one column to be shown, but it has be on a combo box, which now can only show single record not the list. I used a TextBox as test to link the adodc. It shows exactly same as the combobox does. This means the combobox can just function as a textbox, not function as a real combobox ( it shows only blank dropdown list).

    David

  6. #6
    New Lounger
    Join Date
    Apr 2002
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ComboBox - ADODC - DB (VB6)

    What Charlotte meant is DataCombo component which is part of Microsoft DataList Controls.

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ComboBox - ADODC - DB (VB6)

    Since you're using the ADODataControl, I assumed you were using the matching DataCombo, not just a regular VB combobox, just as Olga suspected. If you're using a regular combobox, you have to populate the list from code using the .AddItem method. You can actually enter the List values from the property sheet, but that gives you no ability to add to the list automatically.

    In your situation, you probably would want to open a recordset and loop through it to populate the combobox's list, and you would do that in the Load event of the Form.
    Charlotte

  8. #8
    Lounger
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ComboBox - ADODC - DB (VB6)

    Thanks Charlotte.

    As mentioned in my second post, I did try to use AddItem method in loop and used recordset variable but failed. Can you give me a bit more details about how to do this? As recordset variable contains a collection of record but Additem requires a single item to add each time in the loop, I didnt find what property/method for rs variable to meet the requirement of AddItem.

    David

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ComboBox - ADODC - DB (VB6)

    I'm not sure what you mean. The general code would be something like this:

    <pre>Do While Not rs.EOF
    Combo1.AddItem rs!DataField
    rs.MoveNext
    Loop</pre>


    You might want to use a secondary index on the list, in which case, you would need to dim a numeric variable and use it like this within each loop right after the AddItem method:

    <pre> Combo1.ItemData(Combo1.NewIndex) = intLoop
    intLoop = intLoop + 1</pre>

    Charlotte

  10. #10
    Lounger
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ComboBox - ADODC - DB (VB6)

    I think "AddItem rs!DataField" is what the sytax I looked for.
    However, my code still doesnt work now. Perhaps something wrong for my variable setting for recordset?
    Once I run the code, error msg shows up: Unable to bind to field or DataMember: 'Movie_name'.
    When click OK, it comes out: runtime error '3265' : Item cannot be found in the collection corresponding to the requested name or ordinal. Click Debug button will highlight
    the line of "cboMovie.AddItem rs!DataField".

    Here is my code:

    Dim intLoop As Integer
    Dim rs As ADODB.Recordset

    Set rs = adoMovie.Recordset 'adoMovie is adodc which connected to Access 2000 DB and
    'its RecordSource property binds with a simple SQL statement
    rs.MoveFirst

    Do While Not rs.EOF

    cboMovie.AddItem rs!DataField 'cboMovie is the combobox.
    cboMovie.ItemData(cboMovie.NewIndex) = intLoop
    intLoop = intLoop + 1

    rs.MoveNext
    Loop


    Where is wrong in my code?

    Thanks,

    David

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ComboBox - ADODC - DB (VB6)

    It sounds like you have a different problem. Is Movie_Name the field bound the combo to?
    Charlotte

  12. #12
    Lounger
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ComboBox - ADODC - DB (VB6)

    Yes, Movie_name is the field name bound to the combobox. pleas refer to my post on april 3.

    david

  13. #13
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ComboBox - ADODC - DB (VB6)

    Sorry, it's a little hard to keep all this straight when I only pop in one a day or so. I missed the fact that you were trying to populate the list using the datacontrol's recordset.

    It is much easier to use the datacombo that matches the type of datacontrol. When you do that, you can populate the list by setting its rowsource to a dataenvironment, its rowmember to a table in a dataenvironment and its ListField property to a field in that table. You don't have to use AddItem at all.
    Charlotte

Posting Permissions

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