-
With this code, I've made a control at runtime.
Set btnObj = Controls.Add("VB.ComboBox", sControlName)
With btnObj
.Visible = True
.Width = 2000
.Top = 210 + (i * 350)
.Left = 5500
.ForeColor = vbBlack
.Text = ""
End With
Now I want to remove it. So I thought to set it equal to Nothing:
Set btnObj = Nothing
The problem is, that the control is still on my form.
How can I realy remove it?
-
Just a thought .
Change it's visible property and then set it to nothing .
[]P
-
-
The Unload solution doesn't seems to work.
first I've set the visible property to false
and then I set it on nothing.
When I want to add a new control with te same name as the one I deleted, I get an error which said "Object with this name already exists".
So it seems that the 'Nothing' not realy destroys the object.
Some solution?
-
As it is a Collection you should have access to the Remove method. i.e. Controls.Remove sControlName
Cheers,
P.
-
Try this api call!
Code:
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub RemoveMe(Handle As Long)
DestroyWindow Handle
End Sub
'usage:
'RemoveMe btnObj.hWnd
-
Controls has a property called Remove.
Code:
Controls.Remove ("sControlName")