Is there a way to delete a control at runtime and also a way to check if a control exists? I have a list of buttons that are populated with text from a database and I name the buttons using a loop (ex. "BUTTON" & i, this gives me a list of buttons like BUTTON1, BUTTON2, etc.) When I re-open the form, I need to delete the old buttons (because they link to old information) and start from scratch creating new buttons. How can I just check to see if the button exists and then delete all of the buttons from the form at runtime?
When you add the buttons, add their names to an ArrayList. Now you will be able to check if a specific button exists. Use the Dispose method to delete a control. Something like: For i = 0 To ArrayList1.Count-1 Control(ArrayList1.Item(i)).Dispose Next ArrayList1.Clear
You need to Dispose of the control. I'm not familiar with finding out whether the control exists in the first place though. You could just try to Dispose of all the controls and trap/ignore the error that would be generated if the control wasn't present. I also believe that Disposing of a Form will Dispose of all controls that were present on it. This may have changed with version 5 though?? EDIT: I replied at the samtime as Erel, sorry. As normal I prefer Erel's solution. Regards, RandomCoder.
If the control doesn't exist a error is generated so u can use errorlabel to catch that.. I've done something similar like this: sub controlsdispose For i= 1 to whatever you like, but be sure to be over your last button i ErrorLabel("Error") Control("Button"&i).dispose next i error: If u whant u can do something upon error end sub