PDA

View Full Version : How to check whether a control is having a property?



prabhafriend
07-22-2010, 02:37 AM
Say Controlsource.
For a single control its easy
On Error Resume Next
Msgbox Control.Controlsource
Msgbox "Control Don't have that property"

The problem comes here,
For each control in codecontextobject.controls
On Error Goto NextControl
Msgbox Control.Controlsource
Nextcontrol:
Next control

I want to know either how to trap continous errors else some workaround for this. Kindly help.

Imdabaum
07-22-2010, 10:23 AM
Is this related to your previous post on identifying which controls have controlsource?

If not, then I would suggest running it once and instead
On Error Goto NextControl
Msgbox Control.Controlsource
Nextcontrol:
Next control

Try:
On Error Goto NextControl
Msgbox Control.Controlsource
Nextcontrol:
Msgbox Err.Number
Next control

This will let you see the error number you need to trap.
Then in

NextControl:
If Err.number = [insert the number you receive from the message box]
'Ignore the fact that the control doesn't have the property, and don't do anything.
'Just get the next control
Resume Next
Else
'show the error and take appropriate actions to fix your code/data.
Exit Sub/Function
End If

geekgirlau
07-22-2010, 05:26 PM
This has already been answered here (http://www.vbaexpress.com/forum/showthread.php?p=220157#post220157). You use ControlType to restrict your loop to the types of controls that will have a data source.