I don't understand why you need the line number (ID), if you have the recipe name (I assume you mean bar code) then you have already found it.
Here is a snippet of one I did some years ago.
There is a combo box in the code before that I populate with the recipe name this would be the same as your bar code in effect, so the operator is given a list box of all recipes stored, the operator selects the recipe and the code attached (well this is part of it, as it is far more complicated with linked fields).
So it loads all the values in the row, no need for the id providing the bar code name is unique which I assume would have to be or how would you select which one.
Here we select the recipe stages based on the recipe name and load them into internal tags (thisis required on my system as there is some processing to do before putting the data into the PLC Tags.
Note: the underscore is a way of splitting the string and ignoring Carriage return that the editor puts in, it makes reading the string easier but could be just one long string without the _.
SQLStr = "SELECT * FROM Recipe_Stages " _
& "WHERE Rec_Name='" & Format$(RequestedRecName) & "' " _
& "ORDER BY Stage_Num"
Rs1.Open SQLStr,Conn1,,,
While Not Rs1.EOF
For i = 1 To uRecipe.StagesUsed
With uRecipe.Stages(i)
.IngType = Rs1!Ingredient_Type
.NumIngs = Rs1!Num_Ingredients
.WeightTotal = Rs1!Weight_Total
.WeightTol = Rs1!Weight_Tol
.TempTarg = Rs1!Temperature
.BldStatus = Rs1!Blender_Status
.BldSpeed = Rs1!Blender_Speed
.AgStatus = Rs1!Agitator_Status
.AgSpeed = Rs1!Agitator_Speed
.Duration = Rs1!Duration
.CookOn = Rs1!Cook_On
.Reduction = Rs1!Reduction
.BulkYield = Rs1!Bulk_Yield
End With
Rs1.MoveNext
Next
Wend
Rs1.Close
This is of course far more complex than what you are doing but the principle is the same.
Here is a snippet of where we log the batch details to the database, although this populates it you can see the way we format the query string using quotes which is the same as reading the recipe
Dim GroupStr1,SQLStr, BatchIDStr,Pass,UpTime,UpWeight,UpReqWeight,UpTemp,UpReqTemp,Stage As String
Dim Rs1 As New ADODB.Recordset
Dim Conn1 As New ADODB.Connection
Dim Times,r As Integer
Dim Weight, ReqWeight,Temp,ReqTemp As Double
Sub Main()
On Error GoTo Err
Pass = This.GetParameter(0)
Select Case Pass
Case "1"
GroupStr1 = "CK1_CK1_"
Case "2"
GroupStr1 = "CK2_CK2_"
Case "3"
GroupStr1 = "CK2_CK2_"
End Select
Stage = CStr(GetVariableValue(GroupStr1 & "Scada_Store_Stage_Num"))
BatchIDStr = GetVariableValue(GroupStr1 & "Cooker_Batch_Code")
UpTime = "S" & Stage & "Time"
UpWeight = "S" & Stage & "Weight"
UpReqWeight = "S" & Stage & "ReqWeight"
UpTemp = "S" & Stage & "Temp"
UpReqTemp = "S" & Stage & "ReqTemp"
Times = GetVariableValue(GroupStr1 & "Scada_Store_Stage_Duration")
Weight = GetVariableValue(GroupStr1 & "Scada_Store_Stage_Weight")
ReqWeight = GetVariableValue(GroupStr1 & "Scada_Store_Stage_ReqWeight")
Temp = GetVariableValue(GroupStr1 & "Scada_Store_Stage_Temp")
ReqTemp = GetVariableValue(GroupStr1 & "Scada_Store_Stage_ReqTemp")
Conn1.ConnectionString = "dsn=SP3DB;uid='sa';pwd='';"
SQLStr = "UPDATE Cooker_Batch SET " & UpTime & " =" & Times & ", " & UpWeight & " =" & Weight & ", " & UpReqWeight & " = " & ReqWeight & ", " & UpTemp & " = " & Temp & ", " & UpReqTemp & " = " & ReqTemp & " Where BatchID =" & BatchIDStr & "
Conn1.Open
Conn1.Execute SQLStr
Conn1.Close
Set Conn1 =Nothing
SetVariableValue(GroupStr1 & "Scada_Stage_Complete_Trig",False)
Debug.Print Str(Error) + " Batch Stage " & Stage & " Added For Cooker " & Pass
Exit Sub
Err:
Debug.Print Str(Error) + " Batch Stage Log Failed For Cooker " & Pass
SetVariableValue(GroupStr1 & "Scada_Stage_Complete_Trig",False)
Exit Sub
End Sub