Visual Basic 6 Combo Box Help

Play Now

Elijah

Crystal Dev
Developer
Jul 21, 2004
1,806
18
265
Basically, im reading and writing values to a database, much like a address book infact.

But what im wanting to do is, be able to select a certain record using a combo box.

Im wanting the combo box to populate with all the (AUTONUMBER) ID collumn.

so i can select which number and it will bring up all the information in the selected area's of the form.

I can read and write information perfectly, all im wanting help with is the ComboBox, i can only get it to read the ID number the record im currently looking at.

So im just wanting to know how to populate with ALL the ID Numbers on my database..

Hope you can understand what i'm wanting.

Thanks in advance

/Tofas
 

LeoCrasher

Former Administrator
VIP
Mar 23, 2003
2,001
4
215
::1
It really depends how your accessing your data. Is it a datacontrol with datasourced textboxes, ADO or ADO+SQL?

For a quick reply, I'll assume your using a datacontrol.

Code:
    cmbIDLIst.Clear                                                'Clears the listbox
    datMyDB.Recordset.MoveFirst                       'Moves to first record in DB
    
    Do Until datMyDB.Recordset.EOF = True
    'Searches through DB then it places them in the combobox

        cmbIDList.AddItem datMyDB.recordset.fields(0)                       'assumes 0 is ID field
        datMyDB.Recordset.MoveNext                'Moves to the next record

    Loop

You will need more code to make the record shift after you've selected the new item. You may also need to remove the Data* fields from the combobox.

Btw, is this AS Computing?

/Leo
 

Elijah

Crystal Dev
Developer
Jul 21, 2004
1,806
18
265
It really depends how your accessing your data. Is it a datacontrol with datasourced textboxes, ADO or ADO+SQL?

For a quick reply, I'll assume your using a datacontrol.

Code:
    cmbIDLIst.Clear                                                'Clears the listbox
    datMyDB.Recordset.MoveFirst                       'Moves to first record in DB
    
    Do Until datMyDB.Recordset.EOF = True
    'Searches through DB then it places them in the combobox

        cmbIDList.AddItem datMyDB.recordset.fields(0)                       'assumes 0 is ID field
        datMyDB.Recordset.MoveNext                'Moves to the next record

    Loop
You will need more code to make the record shift after you've selected the new item. You may also need to remove the Data* fields from the combobox.

Btw, is this AS Computing?

/Leo

ADO*

No, its a personal project, learning VB by myself, and on the way im making this program for a shop i work at to record repairs etc.

So whats code now im using ADO?

Thanks

/Tofas
 

LeoCrasher

Former Administrator
VIP
Mar 23, 2003
2,001
4
215
::1
Well I'll assume you've got your entire system working. Within your ADO code for reading data, place this inside the open connection;

Code:
    rs.Open "SELECT * FROM Massacre WHERE Players > 100", CNN

    'Loop through record recsults
    With rs
        .MoveFirst
        
        Do Until .EOF
            cmbBox1.AddItem .Fields(0).Value
            .MoveNext
        Loop
        
        If (.State And adStateOpen) = adStateOpen Then .Close
    End With
    Set rs = Nothing

It will really depend on what you've got as your ADO wrapper whether my idea works or not. Failing that send the project over and I'll amend an example.

/Leo
 

Elijah

Crystal Dev
Developer
Jul 21, 2004
1,806
18
265
Well I'll assume you've got your entire system working. Within your ADO code for reading data, place this inside the open connection;

Code:
    rs.Open "SELECT * FROM Massacre WHERE Players > 100", CNN

    'Loop through record recsults
    With rs
        .MoveFirst
        
        Do Until .EOF
            cmbBox1.AddItem .Fields(0).Value
            .MoveNext
        Loop
        
        If (.State And adStateOpen) = adStateOpen Then .Close
    End With
    Set rs = Nothing
It will really depend on what you've got as your ADO wrapper whether my idea works or not. Failing that send the project over and I'll amend an example.

/Leo

Fancy adding me on msn? I'm a little confused, ill have to explain more how i've got it set up.

I've sent you a pm with my msn addy.

Cheers,

/Tofas