Need Help Identifying Conrol Causing Error

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
 
B

Bill Mosca

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.
 
I

InvisibleDuncan

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 )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top