Need Help Identifying Conrol Causing Error

  • Thread starter Thread starter Sharkbyte
  • Start date Start date
S

Sharkbyte

I'm running the following code:

For Each ctl In frm.Controls
With ctl
If .ControlType = acTextBox Then
If .Tag = 2 Then
Else
.Enabled = True
.Value = .DefaultValue
End If
End If
End With
Next

I'm getting an error, on .Value, for a control identified only by acTextBox
returning a value of 109.

Is there a way to identify which control is being referenced?

Thanks for your help.

Sharkbyte
 
Sharkbyte

Sure. Make sure any "On Error GoTo..." line is commented out. When the error
happens the code will break. hover your mouse pointer over ctl and it should
show the name. If not, when the code breaks type ?ctrl.Name in the immediate
window (press Ctrl+G to open the window) and press Enter.
 
Alternatively, if you've got too many layers of error handlers, write the
control's name to a variable and get your error handler to output that:

On Error GoTo ErrorHandler
For Each ctl In frm.Controls
With ctl
If .ControlType = acTextBox Then
If .Tag = 2 Then
Else
.Enabled = True
strControlName = .Name
.Value = .DefaultValue
End If
End If
End With
Next

ErrorHandler:
MsgBox(strControlName )
 
Back
Top