Results 1 to 9 of 9
  1. #1
    Voodeux2014 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Location
    Slidell, LA
    Posts
    130

    Angry Item Not Found In This Collection (ListBox)

    I am getting the error of "Item not found in this collection" on my listbox. I have listed code and row source information below.



    Code:
    Private Sub cmdFinish_Click() 
    Dim MyDB As dao.Database
    Dim varItem As Variant
    Dim lst As ListBox
    
    
    Dim rst As dao.Recordset
    
    
    If lstApprovedClasses.ItemsSelected.Count = 0 Then
    MsgBox "Please select at least 1 (one) class to add to this grant.", vbOKOnly, "Error"
    Exit Sub
    End If
    
    
    Set MyDB = CurrentDb
    Set rst = MyDB.OpenRecordset("tbl2GrantTrainers", dbOpenDynaset, dbAppendOnly)
    
    
    With rst
    For Each varItem In lstApprovedClasses.ItemsSelected
    .AddNew
    ![GrantID] = [Forms]![frmAddNewGrant]![ID]
    ![ClassID] = lstApprovedClasses.ItemData(varItem)
    ![CurSuggestedHours] = InputBox("Enter suggested hours for [lstApprovedClasses(varItem)", "Suggested Course Length")
    ![CurMaxApprovedSeats] = InputBox("Enter available seats for [lstApprovedClasses(varItem)", "Available Seats")
    .Update
    Next varItem
    End With
    
    
    rst.Close
    Set rst = Nothing
    
    
    MsgBox "The training providers have been successfully added to the new grant.", vInformation, "Information"
    
    
    DoCmd.Maximize
    End Sub
    I am getting the error on this line:
    Code:
    ![ClassID] = lstApprovedClasses.ItemData(varItem)

    Here is the SQL statement for the listbox (lstApprovedClasses):
    SELECT tbl2TrainingOffered.ClassID, tbl1Classes.ClassName FROM tbl1Classes INNER JOIN tbl2TrainingOffered ON tbl1Classes.ClassID = tbl2TrainingOffered.ClassID WHERE (((tbl2TrainingOffered.ProviderID)=[Forms]![frmAddClassestoGrant]![cboTrainingProvider])) ORDER BY tbl1Classes.ClassName;

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The error would imply that ClassID is not a field in the table the recordset was opened on. Is it?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

  4. #4
    Voodeux2014 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Location
    Slidell, LA
    Posts
    130
    thanks pbaldy, didnt even think to look at that. I copied code from a different ocations and didnt change the data i wanted it to be looking into. Thanks!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Voodeux2014 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Location
    Slidell, LA
    Posts
    130
    I know I marked this complete, but I would like to know for the InputBoxes I have coming into play for each selection in the listbox, if there is a way to display which selection the InputBox is for?

    for example:

    "Please enter the available seats for [class name displayed here]."

    The ListBox is bound to the ClassID, but displays the ClassName. Is there a way to have the InputBox display the ClassName for the current selection that is is in the "For each varItem" loop?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Hey, you already marked this as solved!!

    Presuming the name is in the second column try:

    "Please...for " & lstApprovedClasses.Column(1, varItem)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Voodeux2014 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Location
    Slidell, LA
    Posts
    130
    Worked Brilliantly! Thanks again!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. item not found in this collection
    By rockell333 in forum Queries
    Replies: 1
    Last Post: 09-24-2015, 03:20 PM
  2. Replies: 8
    Last Post: 08-18-2015, 04:35 PM
  3. Item Not Found In Collection For TableDefs
    By gammaman in forum Modules
    Replies: 2
    Last Post: 06-17-2015, 07:55 AM
  4. Replies: 7
    Last Post: 06-05-2012, 03:22 PM
  5. Item not found
    By thart21 in forum Programming
    Replies: 7
    Last Post: 04-14-2010, 10:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums