Results 1 to 3 of 3
  1. #1
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    172

    Item not found in collection

    The following procedure produces the error "Item not found in collection" on the line Forms![frmRecipes]![sfIngredients].Controls(strToField) = rst!Controls(strFromField).
    The left side of the equation "Forms![frmRecipes]![sfIngredients].Controls(strToField)" works. The field names on the form are fDblING101 thru fDblING110.
    the proble is on the right side of the equation. This is where I get the error. Those field names are fDblLUI101 thru fDblLUI110.
    Below is the entire procedure. I hope I am not giving you too much info. Thanks in advance.


    Private Sub ctrlIngredients_Click() ' gets data fron tblLookupIngredients and populate form

    Dim strToField As String
    Dim strFromField As String
    Dim x As Long
    Dim strIngredient As String
    Dim db As Database
    Dim rst As Recordset
    Set db = DBEngine(0)(0)
    Set rst = db.OpenRecordset("tblLookupIngredients", dbOpenDynaset)

    strIngredient = Forms![frmRecipes]![sfIngredients].Form![fStrSidesIngredients]


    With rst
    .FindFirst "[fStrSidesIngredients] = '" & strIngredient & "'"
    If Not .NoMatch Then
    Forms![frmRecipes]![sfIngredients].Form![fTxtMeasure] = ![fTxtStandardUnit]
    ' fill in the nutritents
    For x = 101 To 110
    strToField = "fDblING" & CStr(x)
    strFromField = "fDblLUI" & CStr(x)
    Forms![frmRecipes]![sfIngredients].Controls(strToField) = rst!Controls(strFromField)
    ' Forms![frmRecipes]![sfIngredients].Controls(strToField) = ![fDblLUI101]
    Next x
    End If
    End With
    rst.Close
    Set rst = Nothing
    Set db = Nothing



    End Sub

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Recordsets have a .Fields collection not .Controls
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    172
    That is what I needed. Thank you very much.

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

Similar Threads

  1. Replies: 11
    Last Post: 02-02-2019, 11:54 PM
  2. Item not found in this collection
    By Niko in forum Forms
    Replies: 12
    Last Post: 10-13-2017, 03:13 PM
  3. Item Not Found In This Collection (ListBox)
    By Voodeux2014 in forum Forms
    Replies: 8
    Last Post: 10-19-2015, 11:09 AM
  4. item not found in this collection
    By rockell333 in forum Queries
    Replies: 1
    Last Post: 09-24-2015, 03:20 PM
  5. Item Not Found In Collection For TableDefs
    By gammaman in forum Modules
    Replies: 2
    Last Post: 06-17-2015, 07:55 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