Function dlookup(strFieldName, strTableName, strWhere, objConn) '參考access VBA 中的Dlookup函數 '由于環(huán)境不同,加了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