VB下判断控件是否存在的函数


'*******************************************************
'*函数功能:判断控件是否存在的函数
'*参        数:frmObject    窗体名
'*                  strControlsName   待判断的控件名
'*                  lngIndex                 控件Index         非数组控件可省略该参数
'*返  回  值:True 存在    False  不存在
'*******************************************************
Function fChkControls(frmObject As Form, strControlsName As String, Optional lngIndex As Long = -1) As Boolean
On Error GoTo Err
    Dim strContrName As String
    If lngIndex >= 0 Then
        strContrName = frmObject.Controls(strControlsName)(lngIndex).Name
    Else
        strContrName = frmObject.Controls(strControlsName).Name
    End If
    fChkControls = True
    Exit Function
Err:
    fChkControls = False
End Function
原文地址:https://www.cnblogs.com/topboy168/p/823709.html