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
ASP自定义函数,仿VBA中域函数 DLookup
最新推荐文章于 2017-04-22 16:27:15 发布
博客展示了一个自定义的Dlookup函数的VBA代码。该函数参考Access VBA中的Dlookup函数,因环境不同加入ObjConn参数,调用外部自定义函数checksql()处理字段名,通过SQL语句查询数据,还调用自定义函数NZ处理结果,若出错则输出错误信息。
1694

被折叠的 条评论
为什么被折叠?



