經本人測度. AC 自帶 Dlookup ,Dmax 與 用 ADO 編寫的相應的替代函數 , 速度 比較結果如下.
先便出 用 ADO 寫的相應的 替代函數.
Public Conn As New ADODB.Connection 'Conn
'mLookUp 替代 AC中的 Dlookup
Public Function mLookUp(ByVal strFieldName As String, ByVal strTableName As String, Optional ByVal strWhere As String) As Variant
Dim sql As String
sql = "select " & strFieldName & " From " & strTableName
If Len(strWhere) > 0 Then sql = sql & " where " & strWhere
On Error Resume Next
mLookUp = Conn.Execute(sql)(0)
If Err <> 0 Then
Err.Clear
mLookUp = Null
End If
End Function
'mMax 替代 AC中的 DMax
Public Function mMax(ByVal strFieldName As String, ByVal strTableName As String, Optional ByVal strWhere As String) As Variant
Dim sql As String
sql = "select Max(" & strFieldName & ") From " & strTableName
If Len(strWhere) > 0 Then sql = sql & " where " & strWhere
On Error Resume Next
mMax = Conn.Execute(sql)(0)
If Err <> 0 Then
Err.Clear
mMax = Null
End If
End Function
Public Function OpenConn() As Boolean
On Error Resume Next
Set Conn = CurrentProject.Connection
'Conn.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = \\Server\all_user\TOFuyvn\db1.mdb"
If Conn.State = adStateClosed Then
OpenConn = False
Else
OpenConn = True
End If
End Function
測度結果:
具體數據就不一一例出. 我在群中都有發過.
結論:
如果數據庫在本機上 : Dlookup 及 DMax 比 mLookup 及 mMax 要快 70% 左右.
如果數據庫 在 局域網中的 其它電腦上, 將表 連接到 本機上: mLookup 及 mMax 比 Dlookup 及 DMax 快5 倍以上.
如果是 ADP 遠程連接 SQL 數據庫: mLookup 及 mMax 比 Dlookup 及 DMax 快 4 倍以上.
以上只是本人 自己測試的 結論, 不代表其它人的意見. 只做 參考用.