PC Review


Reply
Thread Tools Rate Thread

Control Focus

 
 
Monty
Guest
Posts: n/a
 
      12th Dec 2006
How can I programmatically detect is a particular control has focus?
Is there something like a "HasFocus" property I can test?

Thanks

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      12th Dec 2006
"Monty" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> How can I programmatically detect is a particular control has focus?
> Is there something like a "HasFocus" property I can test?


There's no HasFocus property, but the form has an ActiveControl property
that returns an object reference to the control on the form (if any)
that currently has the focus. So you could write a function like this:

'----- start of code -----
Function HasFocus( _
ctl As Access.Control, _
frm As Access.Form) _
As Boolean

On Error Resume Next
If ctl Is frm.ActiveControl Then
HasFocus = True
End If

End Function

'----- end of code -----

And use it like this:

If HasFocus(Me.Text1, Me) Then
' Text1 has the focus.
End If

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      12th Dec 2006
On 12 Dec 2006 11:07:58 -0800, Monty wrote:

> How can I programmatically detect is a particular control has focus?
> Is there something like a "HasFocus" property I can test?
>
> Thanks


Why you wish to do this would have been helpful.
As it is, code a command button click event:
MsgBox IIf(Screen.Previouscontrol = "WhatControl","Yes What Control
has focus","No " & Screen.PreviousControl.Name & " had focus"))
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
Monty
Guest
Posts: n/a
 
      12th Dec 2006

Dirk Goldgar wrote:
> "Monty" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)
> > How can I programmatically detect is a particular control has focus?
> > Is there something like a "HasFocus" property I can test?

>
> There's no HasFocus property, but the form has an ActiveControl property
> that returns an object reference to the control on the form (if any)
> that currently has the focus. So you could write a function like this:
>
> '----- start of code -----
> Function HasFocus( _
> ctl As Access.Control, _
> frm As Access.Form) _
> As Boolean
>
> On Error Resume Next
> If ctl Is frm.ActiveControl Then
> HasFocus = True
> End If
>
> End Function
>
> '----- end of code -----
>
> And use it like this:
>
> If HasFocus(Me.Text1, Me) Then
> ' Text1 has the focus.
> End If
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)


Thanks, that is exactly what I asked for. But I realize I asked the
wrong question once I looked over your procedure. I've posted the real
question as another topic.

 
Reply With Quote
 
Monty
Guest
Posts: n/a
 
      12th Dec 2006

fredg wrote:
> On 12 Dec 2006 11:07:58 -0800, Monty wrote:
>
> > How can I programmatically detect is a particular control has focus?
> > Is there something like a "HasFocus" property I can test?
> >
> > Thanks

>
> Why you wish to do this would have been helpful.
> As it is, code a command button click event:
> MsgBox IIf(Screen.Previouscontrol = "WhatControl","Yes What Control
> has focus","No " & Screen.PreviousControl.Name & " had focus"))
> --
> Fred
> Please respond only to this newsgroup.
> I do not reply to personal e-mail


I realized my question wasn't very complete, or even accurate, when I
read the first response. I rephrased my question and submitted it as a
new post "Soliciting procedural advice".

Thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
emulating window.focus in Body onload() event and setting focus to a control on same page Jason Microsoft ASP .NET 4 7th May 2007 06:54 PM
giving control focus = Focus? Select? ActiveControl? Activate? Zytan Microsoft VB .NET 9 19th Feb 2007 01:42 AM
Control's, Focus, and Change focus Jon Slaughter Microsoft C# .NET 4 19th Nov 2006 12:31 PM
Losing focus on a slider control within a user control Israel Microsoft Dot NET 1 22nd Mar 2006 04:03 PM
Child control (in user control) regains focus when it is hidden! =?Utf-8?B?cmx0NjI0Ng==?= Microsoft Dot NET Framework Forms 0 14th Aug 2004 11:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:19 PM.