目前是用for each ...next 来遍历控件对像,直到找到控件的名称与想要找的名称一致,找到就退出,没有找到就提示没有;代码如下:
dim fm as object, A as control, CpID as long
set fm=Screen.Activeform
for each A in fm.Controls
if A.name="产品ID" then
CPid=nz(A.value,0)
exit for
end if
next
set fm=nothing
private function checkControl(strName as string) as boolean
On Error goto Err_Handler
dim str as string
str=Me.Controls(strName).Name '取窗体对应控件的名称,如果没有该控件就会报错,就相当于返回False
checkTextbox=true
Err_Handler:
end function
写成自定义函数,随时调用不就可以了吗?
Public Function ExistCtrl(ByVal frm As Form, ByVal ctrlname As String) As Boolean
Dim ctrl As Control
Dim B As Boolean
B = False
For Each ctrl In frm.Controls
If ctrl.Name = ctrlname Then
B = True
Exit For
End If
Next
Set ctrl = Nothing
ExistCtrl = B
End Function