Solved

GotFocus

Posted on 2000-02-16
11
294 Views
Last Modified: 2010-05-02
I couldn't get GotFocus() to work, so I tried going to the extreme and put the following code on my main form:

Private Sub Form_GotFocus()
 End
End Sub

However, the program never ends regardless of whether I load another form and switch back, or switch to another program.

Any ideas?
0
Comment
Question by:aerelorn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 22

Expert Comment

by:ture
ID: 2528897
aerelorn,

The form doesn't get focus if there are objects on it that can get the focus.

If you have a simple form with nothing at all on it and show that form, the event procedure will run.

Ture Magnusson
Karlstad, Sweden
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2528938
From Help
"A form receives the focus only when all visible controls are disabled."

Therefore the form will not get this event as long as there are any controls on the form capable of getting the focus.
0
 
LVL 22

Expert Comment

by:ture
ID: 2528945
:o)
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2528946
You can subclass the form to see when it gets the focus:

"HOWTO: Determine When Your Application Gains or Loses Focus"

http://support.microsoft.com/support/kb/articles/Q186/9/08.ASP
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2528950
:^)
0
 
LVL 6

Expert Comment

by:Marine
ID: 2529183
One more thing to be pointed out , never use END within your application. END terminates the program without firing TERMINATE EVENT what this means is that the memory doesn't get released cauing memory leack. Always either unload them or find anohter way to release the resources.
0
 

Expert Comment

by:TheEmpire
ID: 2530115
Use a picture box and set its size & properties to match your form, then use the gotfocus event as you wish. Also you may want to set its tab index to 0.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2531912
Still, the last control with focus will only receive the GotFocus event.  If there is a textbox with focus on the picturebox, when reactivating the form, Text1_GotFocus is fired.
0
 
LVL 4

Expert Comment

by:tmack
ID: 2539294
Couldnt you use the form_activate event to run code when the form is first activated and in a sense have the 'focus'?? Just a thought...

T
0
 

Expert Comment

by:lhquah
ID: 2549472
use Form_activate event instead of form_gotfocus to fire the end command
0
 
LVL 4

Expert Comment

by:tmack
ID: 2552665
uhhh....is there an echo in here?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question