Item not found in the collection

Item not found in the collection

Post by Chrissy Swallo » Tue, 11 May 1999 04:00:00



Hello,

I've run into a problem with a project I'm working on.  I was hoping
somebody here could offer some advice on what I'm doing.
I'm using Windows 95, Visual Basic 5 SP3.
What I'm trying to do is select a name from a list and have information
about the name populate some labels.  What's happening is, after I click on
the name and the app cycles through when it's in my collection object it
will add the Name and the EmpID but it stops on the Title, Boss and
Extension.  It says that the item is not part of the collection.  I've
checked that these columns do exist in my database and that I've named them
correctly and they have the correct datatypes.  I for the life of me cannot
figure out why it's stopping on these three items.  (I remmed each line out
and ran the application unremming them one at a time) I'm alos connecting to
my database using DAO.

I've pasted my code here (Form, CEmployees, CEmployee).  I would greatly
appreciate any insight anybody has to offer. I'm really stuck.


newsgroup.
(Place a period where the word "dot" is.)

Thanks so much in advance,
Chrissy

*********************************
Code on the Form: frmMain
*********************************
Private Employees   As New CEmployees

Private Sub lstEmps_Click()
    If lstEmps.ListIndex <> -1 Then
        Reposition lstEmps.ItemData(lstEmps.ListIndex)
    End If
End Sub

Private Sub Reposition(IID As Long)
    Employees.Reposition IID

    With Employees.CurrentObject
        lblTitle.Caption = .Title
        lblBoss.Caption = .Boss
        lblExt.Caption = .Extension
        lblEmpID.Caption = .EmpID
    End With
End Sub

Private Sub cboDept_Click()
    lstEmps.Clear
    If cboDept.Text = "" Then Exit Sub
    'clear out the contents of the listbox

    'pass the DeptID to the qdfDeptList in the collections
    'to run the stored procedure to get the list of names for that
department
    Employees.FillList cboDept, lstEmps
End Sub

Private Sub cboDept_DropDown()
    'clear the combo first to prevent duplicates
    cboDept.Clear

    'call the method that will access the qdfDepts to fill the combo box
    'with the list of departments
    Employees.FillCombo cboDept

End Sub

****************************************
Code in my Employees Collection:(CEmployees)
****************************************
Option Explicit
Private rs As DAO.Recordset
'provide a reference to an individual Employee object
Private Employee As CEmployee

Private Sub Class_Initialize()
    Dim ws As Workspace
    Set ws = Workspaces(0)

    Dim sqls As String

    'open the database
    Set db = ws.OpenDatabase(App.Path & "\it.mdb")

    'set the query strings
    sqls = "SELECT * FROM tblMIS"

    'open the Recordset
    Set rs = db.OpenRecordset(sqls, dbOpenSnapshot)

    Set Employee = New CEmployee
End Sub

Public Property Get CurrentObject() As CEmployee
    'references the current employee object
    Set CurrentObject = Employee
End Property

Public Sub Reposition(IID As Long)
    rs.FindFirst "EmpID = " & IID
    If rs.NoMatch = True Then
        Set Employee = New CEmployee
    Else
        UpdateObject
    End If
End Sub

Private Sub UpdateObject()

'update the Employee object with the values from the recordset
    With Employee
        .Name = rs!Name
        .EmpID = rs!EmpID
        'The app stops here and says that these items are not part of the
collection
        .Title = rs!Title
        .Boss = rs!BossID
        .Extension = rs!Extension
    End With
End Sub

Private Sub Class_Terminate()
'close the database and clean up everything
    db.Close
    Set db = Nothing
    Set Employee = Nothing
End Sub

Public Sub FillCombo(cbo As Control)

   'dim the querydef to the stored query
    Dim qdfDepts As QueryDef

    Set qdfDepts = db.QueryDefs!qryDepts
    Set rs = qdfDepts.OpenRecordset(dbOpenSnapshot)

    rs.MoveFirst

    'run the query to get the info for the combo box
    Do Until rs.EOF
        cbo.AddItem rs!Department
        'set the index to the DeptID which will be needed to populate the
listbox(lstEmps)
        cbo.ItemData(cbo.NewIndex) = rs!DeptID
       rs.MoveNext
    Loop
End Sub

Public Function FillList(cbo As Control, lst As Control)

    Dim qdfDeptList As QueryDef

    Set qdfDeptList = db.QueryDefs!DeptList

     'pass the parameter ID to the query to get the employee listing
    qdfDeptList("ID") = cbo.ItemData(cbo.ListIndex)
    Set rs = qdfDeptList.OpenRecordset(dbOpenSnapshot)

    Do Until rs.EOF
        'this should get the info to fill lstEmps
            lst.AddItem rs!Name
            lst.ItemData(lst.NewIndex) = rs!EmpID
            rs.MoveNext
    Loop
End Function

************************************************
And here is my Employee object:(CEmployee)
************************************************
Private msName As String
Private msTitle As String
Private msExtension As String
Private miDepartment As Integer
Private miBoss As Integer
Private mlEmpID As Long

Private rs As Recordset

Public Property Get EmpID() As Long
    EmpID = mlEmpID
End Property

Public Property Let EmpID(lData As Long)
    mlEmpID = lData
End Property

Public Property Get Name() As String
    Name = msName
End Property

Public Property Let Name(sData As String)
    msName = sData
End Property

Public Property Get Title() As String
    Title = msTitle
End Property

Public Property Let Title(sData As String)
    msTitle = sData
End Property

Public Property Get Extension() As String
    Extension = msExtension
End Property

Public Property Let Extension(sData As String)
    msExtension = sData
End Property

Public Property Get Department() As Integer
    Department = miDepartment
End Property

Public Property Let Department(iData As Integer)
    miDepartment = iData
End Property

Public Property Get Boss() As Integer
    Boss = miBoss
End Property

Public Property Let Boss(iData As Integer)
    miBoss = iData
End Property

Public Sub AddNew()

    Set rs = db.OpenRecordset("tblMIS", dbOpenDynaset)

    'add a new record to the database
    rs.AddNew

    'set the properties of the object
    rs!Name = Me.Name
    rs!Title = Me.Title
    rs!BossID = Me.Boss
    rs!Extension = Me.Extension
    rs!DeptID = Me.Department

    ' save the record
    rs.Update

    rs.Close
    Set rs = Nothing

End Sub