Hello,
I have a number of instances in which I need to grab a single value
from a table based on an index. Usually that table is an attached
table. I know Access provides the DLookup function to do this kind of
thing but I've been fooling around with functions like the abbreviated
one below to do this more efficiently:
Function GetVal(lngIndexID as long) as Variant
Static db as Database
Static rst as RecordSet
' GetRecordSet() returns a table-type recordset in rst and
' a database reference in db for the table named in the first
' argument regardless of whether it is attached or resides
' in the current database.
If rst Is Nothing Then
Call GetRecordSet("tblMyTable", db, rst)
rst.Index = "PrimaryKey"
End If
rst.Seek "=", lngIndexID
GetVal = rst.Fields("MyField")
End Function
My question is if anyone has used this kind of function (using static
db and recordset objects) in a production system and if they've
experienced any negative consequences. For example, I have no idea
how much it costs in terms of memory to maintain static references to
a number of database objects and/or recordset objects or if that
amount of memory changes depending on the characteristics of the
objects themselves, i.e., number of tables, number of fields, etc.
Are there instances where this kind of function ceased to work for
you? It seems to work well in my limited testing at least. Any
comments greatly appreciated. Thanks.
Bruce