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!

Determine iIf a Control Can Have a Value 1

Status
Not open for further replies.

TomHW

Programmer
Sep 8, 2004
100
US
Is there a way, when iterating through a forms controls collection, to determine if a control has a "Value" property?

I am writing a class module to handle default values for controls. In the form's OnOpen event the class is initialized and gets sent the form object. It uses WithEvents to hook up to the forms OnLoad and OnUnload events. When the form loads, the class iterates trhough each control and checks the tag property for the value "default='xxx'" where xxx is the default name. If this tag exists it adds the control to a collection. The class then sets each control in the collection to the default value in a Defaults table that keys off of the xxx portion, or creates a row if it does not exist. During Unload it captures the value from each control and sets it in the Defaults table.

I only want to add controls to the collection if there is a possiblilty of the control having a value. This will make the code more robust by not attempting to take or set a value of a control such as a line or rectangle that has the correct tag value but no value property.

Any help would be greatly appreciated

Thanks,
Tom
 
Why not simply test the ControlType property ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That was my first thought but it requires listing quite a few different ControlTypes to check against and I was hoping for 1) a simpler, more elegant solution and 2) a way to determine if a control has a property in general for future use.

I also considered just adding all correctly tagged controls and then just adding an "On Error Resume Next" before the reading and writing of values but I do not like relying on error handling for proper code functionality.

If you (or anyone else) can think of a way to determine if a property exists let me know, otherwise I will just test the ControlType property as you suggested.

Thanks,
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top