G
Guest
I am returning the Min and Max of field [Period] by making two passes through
the database as follows. It is very slow. How can I speed this up and do it
with one pass and speed up the process also?
Thank you for your help.
'----------------------------------------------------
Dim vMin, vMax As String
vMin = retMin("HistoryFile", "Co = '" & [Forms]![FLookup]![Co] & "'")
vMax = retMax("HistoryFile", "Co = '" & [Forms]![FLookup]![Co] & "'")
Me.Combo40 = vMin
Me.Combo42 = vMax
'---------------------------------
Public Function retMin(TableName As String, WhereClause As String) As String
Dim rs As DAO.Recordset
Dim strSql As String
strSql = "SELECT Min([Period]) As vMinimum " & _
"FROM [" & TableName & "] " & _
"WHERE " & WhereClause
Set rs = CurrentDb.OpenRecordset(strSql)
retMin = rs!vMinimum
rs.Close
Set rs = Nothing
End Function
Public Function retMax(TableName As String, WhereClause As String) As String
Dim rs As DAO.Recordset
Dim strSql As String
strSql = "SELECT Max([Period]) As vMaximum " & _
"FROM [" & TableName & "] " & _
"WHERE " & WhereClause
Set rs = CurrentDb.OpenRecordset(strSql)
retMax = rs!vMaximum
rs.Close
Set rs = Nothing
End Function
the database as follows. It is very slow. How can I speed this up and do it
with one pass and speed up the process also?
Thank you for your help.
'----------------------------------------------------
Dim vMin, vMax As String
vMin = retMin("HistoryFile", "Co = '" & [Forms]![FLookup]![Co] & "'")
vMax = retMax("HistoryFile", "Co = '" & [Forms]![FLookup]![Co] & "'")
Me.Combo40 = vMin
Me.Combo42 = vMax
'---------------------------------
Public Function retMin(TableName As String, WhereClause As String) As String
Dim rs As DAO.Recordset
Dim strSql As String
strSql = "SELECT Min([Period]) As vMinimum " & _
"FROM [" & TableName & "] " & _
"WHERE " & WhereClause
Set rs = CurrentDb.OpenRecordset(strSql)
retMin = rs!vMinimum
rs.Close
Set rs = Nothing
End Function
Public Function retMax(TableName As String, WhereClause As String) As String
Dim rs As DAO.Recordset
Dim strSql As String
strSql = "SELECT Max([Period]) As vMaximum " & _
"FROM [" & TableName & "] " & _
"WHERE " & WhereClause
Set rs = CurrentDb.OpenRecordset(strSql)
retMax = rs!vMaximum
rs.Close
Set rs = Nothing
End Function