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