转自: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群(群号:198465573) |