Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-表

由字段名称求字段标题函数及由字段标题求字段名称函数

时 间:2007-10-26 14:38:58
作 者:放飞梦想   ID:60  城市:南京
摘 要:由字段名称求字段标题函数及由字段标题求字段名称函数
正 文:

转自:office中国 Trynew
由字段名称求字段标题函数及由字段标题求字段名称函数:

Public Function GetFldName(TblName As String, FldCaption As String) As String
On Error Resume Next
Dim rst As DAO.Recordset, i As Integer
Set rst = CurrentDb().OpenRecordset(TblName)
For i = 0 To rst.Fields.Count - 1
If rst.Fields(i).Properties("Caption") = FldCaption Then
GetFldName = rst.Fields(i).Name
Exit For
End If
Next
End Function

Public Function GetFldCaption(TblName As String, FldName As String) As String
On Error Resume Next
Dim rst As DAO.Recordset
Set rst = CurrentDb().OpenRecordset(TblName)
GetFldCaption = rst.Fields(FldName).Properties("Caption")
End Function
如果在窗体内部应用,则不需要表名参数,用Me.Recordset来代替上面函数的Rst即可。

Private Function GetFldName(FldCaption As String) As String
On Error Resume Next
Dim i As Integer
For i = 0 To Me.Recordset.Fields.Count - 1
If Me.Recordset.Fields(i).Properties("Caption") = FldCaption Then
GetFldName = Me.Recordset.Fields(i).Name
Exit For
End If
Next
End Function

Private Function GetFldCaption(FldName As String) As String
GetFldCaption = Me.Recordset.Fields(FldName).Properties("Caption")
End Function

Access软件网QQ交流群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助