Results 1 to 13 of 13

Thread: ComboBox and Database--PLEASE HELP CANT CONTINUE

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    98

    ComboBox and Database--PLEASE HELP CANT CONTINUE

    I have a combo box populated using .additem with three fields from a recordset.

    When the user selects an item how do I determine what record they are on? Can I bind the Combo Box to work like the ADO Control where you can navigate through a recordset by using the combo box?

    I have tried using .itemdata and other properties with no luck.

    There must be a standard way of doing this because combo boxes are used in almost every database.

    ----------------

    Would it be easier to use the DataEnviroment? I havent found much documentation on it. Can it do everything you can do using code to make the connections and generate the recordsets?


    Thank you,
    Coopetj

  2. #2
    Junior Member
    Join Date
    Sep 2000
    Posts
    20
    If you want to link it very closely to an ADO control, you can use a DataCombo box, which ships with VB (just include it in your list of available controls by pressing Ctrl-T).

    Otherwise, if i'm not mistaken, the .ListIndex property will tell you which item has been selected.
    Or if you want the actualy value selected, just use .Text

    With regard to Data environments, i wouldnt recommend one. They are cumbersome and awkward and quite frankly it is far simpler just to use Adodb.Connection and Adodb.Recordset objects in your code.

    Hope this is useful to you.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    98
    How do you bind it to the RS?

    DBCombo1.DataSource = rs
    DBCombo1.DataField = rs.Fields("ClientID")

    The above doesnt work.

  4. #4
    OLa Ali
    Guest

    Combo Boxes

    Before I was facing same problem (How to indecate for specific record within items Filled in Combo Boxes,,

    After long searching i Found good way to solve this problem that you can follow it ..

    1)Build your Recordset from a table(Rs)

    2)Let the First field in the recordset refer to
    the (index_Primary Field in the Table)

    3)manipulate your Comboxes;
    Comb1.AddItem Rs.fields("Name of the Field").valu
    Comb1.ItemData(Comb1.newIndex)=Rs.fields(0).value

    *********

    When user select Specific item from the Comb1 then

    Actually we select the Value of the Primary Field

    On Comb1_Click() event

    Dim Val as Long

    Val=Comb1.itemdata(Comb1.listindex)

    Then searching for Val in the Primary field in the Table..


    Have Good Luck;
    OLA

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    98
    Let me see if I get this

    'Comb1.AddItem Rs.fields("Name of the Field").value

    This just populates the combo box with a field from a rs. What does the .value do? MSDN says "Sets or returns a Variant value. The default value depends on the Type property." I prefer english however.

    'Comb1.ItemData(Comb1.newIndex)=Rs.fields(0).value

    I have no idea what this is doing. For each item in the list there is a corresponding ItemData, correct? Are you setting the Itemdata to the numeric value of the PrimaryKey in the table? What does rs.fields(0).Value represent? Would I just replace the 0 with the field name for the primary key?

    Im not sure what "comb1.newindex" does.

    This seems kinds of complicated for features that are used all the time. You would think there was an easier way to just bind a combo box to a recordset. Ive seen the process you posted used before. I just couldnt remember where I saw it.

    With all the tutorials on the web they all seem to miss the stuff that Newbies REALLY are looking for. I am compiling a list of things I cant find so when/if I get good enough or know someone good enough I an build a tutorial with practical examples.

  6. #6
    sankb
    Guest
    Plez forward your e-mail address , I'll e-mail you a project
    which I'm working on. (I faced the exact problem )
    with Rgds,
    San

  7. #7
    rickm
    Guest

    Re: ComboBox and Database--PLEASE HELP CANT CONTINUE

    Originally posted by coopetj
    I have a combo box populated using .additem with three fields from a recordset.

    When the user selects an item how do I determine what record they are on? Can I bind the Combo Box to work like the ADO Control where you can navigate through a recordset by using the combo box?

    I have tried using .itemdata and other properties with no luck.

    There must be a standard way of doing this because combo boxes are used in almost every database.

    ----------------

    Would it be easier to use the DataEnviroment? I havent found much documentation on it. Can it do everything you can do using code to make the connections and generate the recordsets?


    Thank you,
    Coopetj
    Well, when you do an additem to a combobox, you have an index, if you have a unique numeric field in your database, you can set the index to that, and recall it that way. I have a much more complicated way of doing it, but it requires that you have my classes, and know how to use them.

    Rick

  8. #8
    OLa Ali
    Guest
    Lets Imagine together that we create a table in the DataBase

    Called(My Table)and it has Two Fields,The First one Is a primary Field called(The Code),and the second Field called(Name)..
    -------------------------------------
    The Code Name
    -------------------------------------
    1

  9. #9
    OLa Ali
    Guest

    Wink Combo Boxes...

    Lets Imagine together that we create a table in the DataBase

    Called(My Table)and it has Two Fields,The First one Is a primary Field called(The Code),and the second Field called(Name)..
    -------------------------------------
    The Code Name
    -------------------------------------
    1 Ahmed
    2 OLA
    3 Kholoud
    4 Tom
    5 Adam
    --------------------------------------
    In the Form_Load()Event ..Lets Fill Combo1 with the above Names

    Private Sub Form_Load()

    Dim Rs as ADODB.Recordset

    set Rs=new Recordset

    Rs.Open "MyTable",Con-------->>Con is refer to Connection Object.

    Rs.MoveFirst

    Do Until Rs.Eof

    Combo1.addItem Rs.fields("Name").value---->>Fill the Combo1 with the ----Values of this Field.
    Combo1.ItemData(Combo1.NewIndex)=Rs.Fields("The Code").value

    Rs.moveNext

    Loop

    End Sub
    *******
    In the Combo1_Click()Event

    Private Sub Combo1_Click() event

    Dim Val

    Val=Combo1.ItemData(Combo1.ListIndex).value

    End Sub

    -->>Now this Val Refer to the Value of((The Code))Field

    Hope I could Make it More Clear now..

    Have Good Luck again..Bye

  10. #10
    New Member
    Join Date
    May 2001
    Location
    Been there
    Posts
    8
    Have any of you guy looked into the DBcombobox. It is different than the regular combo box. It has properties for doing these things. like .datalist = "Field to populate the combo box with"

  11. #11
    Junior Member
    Join Date
    May 2001
    Location
    PHilippines
    Posts
    20

    I have a combo box populated using .additem with three fields from a recordset. ...

    try this code:

    With DataCombo
    Set .DataSource = rstMyTable
    .BoundColumn = "MyTable.Field"
    Set .RowSource = rstMyTable
    .ListField = "MyTable.Field"
    End With



  12. #12
    New Member
    Join Date
    May 2001
    Posts
    10

    Re: ComboBox and Database--PLEASE HELP CANT CONTINUE

    Originally posted by coopetj
    [B]I have a combo box populated using .additem with three fields from a recordset.

    When the user selects an item how do I determine what record they are on? Can I bind the Combo Box to work like the ADO Control where you can navigate through a recordset by using the combo box?

    I have tried using .itemdata and other properties with no luck.

    There must be a standard way of doing this because combo boxes are used in almost every database.
    use this... cmb.list(cmb.listindex)
    this will return your current selection...

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    98
    Thanks for all the help guys.

    Its working. I am going to finish my current app before I look into the datacombo box.

    I am now play with the sort method of the recordset object.

    I appreciate all the help,

    T. Cooper

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