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