View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dreiding Dreiding is offline
external usenet poster
 
Posts: 80
Default Can I detect what Control the cursor is at in a form?

I dynamically build a form with textboxes.
Is there a way to detect which text box the cursor is at when a button is
clicked?

Tried and failed with the following code (not a surprise)
Function SelectedControl() as string
Dim ctl As Control
SelectedControl=""
For Each ctl In Me.Controls
If ctl.setfocus = true Then
SelectedControl=ctl.name
exit for
End If
Next ctl
End Sub

I suspect my problem is two-fold.
1. No way to detect current focus (can't read the SetFocus)
2. When the button is clicked, the focus moves..

Any help or suggestions appreciated.
tia, Pat