View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Charles Williams Charles Williams is offline
external usenet poster
 
Posts: 968
Default Need Help to Control the UDF from re-calculation

Hi Steve,

Looks like the time is being used making the connection and executing the
query to get the recordset.

I would suggest that you get the complete recordset (without the filters,
using GROUP BY) once (or once every hour or so if the information in the DB
may change).

Do this by getting the recordset only if it is Nothing, and do not set the
recordset to nothing at the end -

if rs is nothing then
'
' get recordset
'
Set rs = New ADODB.Recordset

STRSQL = "SELECT ... FROM ... GROUP BY ..."
rs.Open STRSQL, G_Connect, adOpenStatic, adLockBatchOptimistic, adCmdText

end if

and then use RS.FIND to get the particular record you want using the Where
Criteria

You may also want to use a disconnected recordset
(RS.CursorLocation=adUseClient before getting the recordset and Set
rs.ActiveConnection = Nothing after getting it)

regards
Charles
_________________________
The Excel Calculation Site
http://www.decisionmodels.com