Combo box Index problem 
Author Message
 Combo box Index problem

Hi,
I have a H/PC 2000 and the data comes from a pocket Access file.
Could somebody please tell me why the index of my combo box doesn't match
the primary key of EntryID and creates a new index starting at 0.
I have similar code working on other combo boxes on the main form that seems
to work fine. The combo box is on a frame, would that make a difference?
My code is as follows:

    ' Fill in combo box for Staff Names
    Set oRecordset = CreateObject("ADOCE.Recordset.3.1")
    oRecordset.Source = "SELECT EntryID, Name FROM tblStaff ORDER BY Name;"
    oRecordset.CursorType = adOpenForwardOnly
    oRecordset.ActiveConnection = oConnection
    oRecordset.Open
    Do While Not oRecordset.EOF
        cboStaff.AddItem oRecordset.Fields("Name")
        cboStaff.ItemData(cboStaff.NewIndex) = oRecordset.Fields("EntryID")
        oRecordset.MoveNext
    Loop
    oRecordset.Close
    Set oRecordset = Nothing

 Please let me know the solution to the problem or any possible reason for
it not to work.

Thank You

Peter



Tue, 18 Jan 2005 07:11:03 GMT  
 Combo box Index problem

Quote:
>         cboStaff.AddItem oRecordset.Fields("Name")
>         cboStaff.ItemData(cboStaff.NewIndex) =

oRecordset.Fields("EntryID")

I did the exact same thing in a project. It didn't work as intended, but
while I were debugging it (using MsgBox) it suddenly started to work. I
hadn't changed any of the real code.
After removing my debug messages again, it continued to work.

Keld Laursen



Tue, 18 Jan 2005 14:09:26 GMT  
 Combo box Index problem
Thanks, for the response Keld

I have been trying over and over and I just can't get the combo box to
return the primary key (EntryID) of my table (tblStaff).
Am I trying to do this the right way, or is there a better way?
All I'm trying to do is look up a table e.g. of staff names, select a name
and store the primary key that matches the name in a second table.
 Somebody please help
Thanks

Peter


Quote:


> >         cboStaff.AddItem oRecordset.Fields("Name")
> >         cboStaff.ItemData(cboStaff.NewIndex) =
> oRecordset.Fields("EntryID")

> I did the exact same thing in a project. It didn't work as intended, but
> while I were debugging it (using MsgBox) it suddenly started to work. I
> hadn't changed any of the real code.
> After removing my debug messages again, it continued to work.

> Keld Laursen



Fri, 21 Jan 2005 05:33:49 GMT  
 Combo box Index problem
All

I've sorted the problem now, I was confused with the combobox properties.
cboStaff.ItemData(cboStaff.ListIndex) Returns the Primary Key
cboStaff.List(cboStaff.ListIndex) Returns the displayed value

Regards
Peter


Quote:
> Thanks, for the response Keld

> I have been trying over and over and I just can't get the combo box to
> return the primary key (EntryID) of my table (tblStaff).
> Am I trying to do this the right way, or is there a better way?
> All I'm trying to do is look up a table e.g. of staff names, select a name
> and store the primary key that matches the name in a second table.
>  Somebody please help
> Thanks

> Peter





> > >         cboStaff.AddItem oRecordset.Fields("Name")
> > >         cboStaff.ItemData(cboStaff.NewIndex) =
> > oRecordset.Fields("EntryID")

> > I did the exact same thing in a project. It didn't work as intended, but
> > while I were debugging it (using MsgBox) it suddenly started to work. I
> > hadn't changed any of the real code.
> > After removing my debug messages again, it continued to work.

> > Keld Laursen



Sat, 22 Jan 2005 05:18:45 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Combo Box Index Problem

2. unbound combo box problems - list index??

3. Combo box Index

4. combo box index

5. COMBO BOX INDEX PROPERTY

6. Problems making a automatic text box when selecting in a combo box

7. Vb 4.0 Problems updating Text Boxes from Combo Box linked to Data Control

8. MatchEntry property problem on combo box and list box

9. enter data in a combo box based on value from another combo box

10. Limit subform combo box by selection in parent combo box

11. Want Access combo box to filter rowsource of another combo box

12. Populating a combo box from another combo box

 

 
Powered by phpBB® Forum Software