我想动态加载Combo,其中有一段代码如下:
IsObject = NewCmbAteCom Is Nothing
If IsObject = False Then
Controls.Remove NewCmbAteCom
Set NewCmbAteCom = Nothing
End IfSet NewCmbAteCom = Controls.Add("VB.ComboBox", "cmbAteCom", Frame1)
NewCmbAteCom.AddItem "COM1", 0
NewCmbAteCom.AddItem "COM2", 1
NewCmbAteCom.Visible = True如NewCmbAteCom=Nothing,此段代码没问题;
但是,NewCmbAteCom不是Nothing,Remove 句在运行时错误,显示:
"The control is no longer usable because it has been removed from the controls collection"不知如何做才能处理这个问题?
哪位帮忙一下,先谢谢了!
IsObject = NewCmbAteCom Is Nothing
If IsObject = False Then
Controls.Remove NewCmbAteCom
Set NewCmbAteCom = Nothing
End IfSet NewCmbAteCom = Controls.Add("VB.ComboBox", "cmbAteCom", Frame1)
NewCmbAteCom.AddItem "COM1", 0
NewCmbAteCom.AddItem "COM2", 1
NewCmbAteCom.Visible = True如NewCmbAteCom=Nothing,此段代码没问题;
但是,NewCmbAteCom不是Nothing,Remove 句在运行时错误,显示:
"The control is no longer usable because it has been removed from the controls collection"不知如何做才能处理这个问题?
哪位帮忙一下,先谢谢了!
on error resume next
-------------------------------------
用 Is Nothing 并不能判断一个控件是否存在
就用resume next了
改成
Controls.Remove "cmbAteCom"
就不会错了。NewCmbAteCom是变量名,而"cmbAteCom"才是控件名!