I've marked the line in this subroutine where I've been getting this error.
It may be something stupid but I've been staring at this error trying to fix
it for over an hour. I'm pretty sure the table and field names and controls
are all named correctly, and the control referred to in the errant code is
open, and it has data in it.
Private Sub cmdAddIngredientToRecipe_Click()
' Get RecipeID for future action query
Dim recipeID As Long
Dim dbGetRecipeID As DAO.Database
Dim rsGetRecipeID As DAO.Recordset
Dim StrSQL As String
Set dbGetRecipeID = CurrentDb()
StrSQL = "SELECT tblRecipes.lngRecipeID FROM tblRecipes WHERE
(((tblRecipes.lngRecipeID)= " & [Forms]![frmRecipes]![lngRecipeID] & "));"
Set rsGetRecipeID = dbGetRecipeID.OpenRecordset(StrSQL, dbOpenDynaset)
recipeID = rsGetRecipeID.Fields(0)
Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing
' This works fine to this point
' Get IngredientID for future action query
Dim IngredientID As Long
Dim dbGetIngredientID As DAO.Database
Dim rsGetIngredientID As DAO.Recordset
'I'm filling variables to use in an append query down later in this
subroutine.
StrSQL = "SELECT tblIngredients.lngIngredientID FROM tblIngredients
WHERE tblIngredients.IngredientName = '" & cboIngredientName & "'"
'IngredientName is a text field.
' The next line is flagged as a problem. I get a run-time error 91" Object
Variable
' or with block variable not set. I'm predicting something is wrong with my
SQL statament on the previous line.
Set rsGetIngredientID = dbGetIngredientID.OpenRecordset(StrSQL,
dbOpenDynaset)
IngredientID = rsGetIngredientID.Fields(0)
Set rsGetRecipeID = Nothing
Set dbGetRecipeID = Nothing
MsgBox IngredientID 'just to test my code this far.
End Sub