ASP自定義函數(shù),仿VBA中域函數(shù)DLookup
發(fā)表時(shí)間:2023-08-18 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]Function dlookup(strFieldName, strTableName, strWhere, objConn) '參考Access VBA 中的Dlookup函數(shù) ...
Function dlookup(strFieldName, strTableName, strWhere, objConn)
'參考Access VBA 中的Dlookup函數(shù)
'由于環(huán)境不同,加了ObjConn參數(shù),直接將Adodb.connection直接調(diào)進(jìn)來(lái)
Dim strsql
Dim rs
Set rs = server.CreateObject("adodb.recordset")
'下面要調(diào)用外部的一個(gè)自定義函數(shù) 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
'要調(diào)用一個(gè)自定義函數(shù) NZ
'詳細(xì)內(nèi)容請(qǐng)參考 ACCESS VBA 幫助中的資料
dlookup = Nz(rs(strFieldName), "")
End If
rs.Close
End Function