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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine Which Control Has Focus 1

Status
Not open for further replies.

Linguist

Technical User
Joined
Jul 11, 2000
Messages
40
Location
US
Background: I am developing an application that has a RichTextBox, 2 TextBoxes, and a DBGrid on the same form.

Problem: I would like to be able to set up a test to determine which of the above controls has focus at any given point in time. Then, depending on which control has focus, the application will procede accordingly.

Any suggestions will be welcome.

Thanks,
-Bob
 
You can use the <formname>.ActiveControl property. This should return you the control name.

Hope this answers your question
 
Thanks for the suggestion.

However, I seem to still have a problem: I don't seem to have any properties available to frmMain.ActiveControl (Name, etc.).

Here is the code for the Sub, so you can see the whole context:

Private Sub btnTranslate_Click()
Dim Temp
Dim strTransText As String
Dim ctlCurrentControl As Control

Set ctlCurrentControl = Screen.ActiveControl
If ctlCurrentControl.Name = &quot;DBGrid1&quot; Then
strTransText = DBGrid1.SelText
ElseIf ctlCurrentControl.Name = &quot;txtSlovene&quot; Then
strTransText = txtSlovene.SelText
ElseIf ctlCurrentControl.Name = &quot;txtEnglish&quot; Then
strTransText = txtEnglish.SelText
End If

Clipboard.SetText strTransText
Temp = Clipboard.GetText()
RichTextBox1.SetFocus
RichTextBox1.Find (strSearchText)
RichTextBox1.SelText = strTransText
End Sub


Thanks,
-Bob
 
Bob,
You can use Me.ActiveControl.Name property to extract the name of the control which has focus, &quot;Me&quot; being the form. Once you get the name of the control, I think you should know what to do, right? Let me know if it worked.

Thanks
Roopam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top