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

【转载】VBA-通过标签确定关联控件

时 间:2023-04-04 10:51:32
作 者:金宇   ID:43  城市:江阴
摘 要:VBA-通过标签确定关联控件。
正 文:

      下面是一个函数,我们可以通过标签来确定与哪个控件相关联,使用的时候先将下面函数放到模块中。

'------------------------------------------------------------------------
' Procedure : GetLabelAssoCtrl
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Req'd Refs: Late Binding  -> none required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' oLbl      : Label object to retrieve the associated control name of
' oFrm      : Form object containing the label control
'
' Return:
' ~~~~~~~
' The function return the name of the associated control, and "" if it isn't associated
' with any control.
'
' Usage:
' ~~~~~~
' GetLabelAssoCtrl(me.lbl_FirstName, me)
'   Returns -> txt_FirstName
'
' Revision History:
' Rev       Date(yyyy-mm-dd)        Description
' **************************************************************
' 1         2023-03-31
'----------------------------------------------------------------
Function GetLabelAssoCtrl(oLbl As Access.Label, oFrm As Access.Form) As String
On Error GoTo Error_Handler
    Dim sAssoCtrl As String
    
    sAssoCtrl = oLbl.Parent.Name
    If oFrm.Name = sAssoCtrl Then sAssoCtrl = ""
    
    GetLabelAssoCtrl = sAssoCtrl
    
Error_Handler_Exit:
    On Error Resume Next
    Exit Function
 
Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Source: GetLabelAssoCtrl" & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function


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

常见问答:

技术分类:

相关资源:

专栏作家

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