I have a recordset of a small file and depending upon values in another file, I retrieve values from the recordset.
Since this process is used frequently in this application, I would like to put it in a function. But since I have opened the recordset in the calling Procedure, the function fails -- I think because it doesn't recognize the open recordset.
My code is:
Please suggest how I could use a function for this process.
I thought about opening and closing the recordset in the function, but since it would be called frequently, I didn't think that would be efficient.
Thanks.
Since this process is used frequently in this application, I would like to put it in a function. But since I have opened the recordset in the calling Procedure, the function fails -- I think because it doesn't recognize the open recordset.
My code is:
Code:
rs.Open "tblTempMfgProductData", CurrentProject.Connection, adOpenStatic
strElement = "Weight"
strSupplier = Left(Trim(Supplier), 6)
'******************************************************
'** I would like this next line to be the function call
' NetWeight = getElement(strSupplier, strElement)
'********************************************************
'** This next section would be the function -- getElement(Supplier, Element)
iRow = DLookup("[Row]", "tblElements", "[Supplier] = '" & strSupplier & "'" _
& " AND [Element] = '" & strElement & "'")
iColumn = DLookup("[Column]", "tblElements", "[Supplier] = '" & strSupplier & "'" _
& " AND [Element] = '" & strElement & "'")
'********************************
' When this is set up as a function, the "rs.movefirst" fails
' because it the recordset is not recognized in the function
rs.MoveFirst
rs.Move (0 + iRow - 1)
NetWeight = rs(iColumn - 1)
Please suggest how I could use a function for this process.
I thought about opening and closing the recordset in the function, but since it would be called frequently, I didn't think that would be efficient.
Thanks.