ASP自定義函數,仿VBA中域函數DLookup
發表時間:2023-08-18 來源:明輝站整理相關軟件相關文章人氣:
[摘要]Function dlookup(strFieldName, strTableName, strWhere, objConn) '參考Access VBA 中的Dlookup函數 ...
Function dlookup(strFieldName, strTableName, strWhere, objConn)
'參考Access VBA 中的Dlookup函數
'由于環境不同,加了ObjConn參數,直接將Adodb.connection直接調進來
Dim strsql
Dim rs
Set rs = server.CreateObject("adodb.recordset")
'下面要調用外部的一個自定義函數 checksql()
strFieldName = checksql(strFieldName)
If strWhere <> "" Then
strWhere = " where " & strWhere
End If
strsql="select "&strfieldname&" from "&strtablename&" " & strwhere
'debugstop strsql
On Error Resume Next
rs.Open strsql, objConn, 1, 1
If Err <> 0 Then
response.write Err.Description
response.end()
End If
If rs.EOF And rs.BOF Then
dlookup = ""
Else
'要調用一個自定義函數 NZ
'詳細內容請參考 ACCESS VBA 幫助中的資料
dlookup = Nz(rs(strFieldName), "")
End If
rs.Close
End Function