Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if form element exists 1

Status
Not open for further replies.

M3Fan

Programmer
Dec 28, 2001
73
US
Hello all-

I'm running into a problem with some existing code here where upon opening a form, certain combo boxes, etc are set to not visible or visible based upon the data populated into the form. The objects with the visibility being set are not always included in the form based on the data as well. Thus, the program blows up trying to set visibility on objects that are not there at times. I realize this is moronic coding, but it is existing code and the form is extremely complicated so I'd like to intrude as little as possible. The easiest solution I can imagine is checking if the form element exists before setting the visibility property. Of course, checking if it exists causes it to blow up if it doesn't. Is there a function that can safely check if the form object exists (combo box, text box, label, etc)???
 
You should be able to use the forms controls collection to check if a control exists. Something like this,

Code:
   Dim MyControl As Control
   
   For Each MyControl In Me.Controls()
      If TypeOf MyControl Is TextBox Then
         If MyControl.Name=?? then
            ....
         End If
      End If
   Next MyControl

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top