Solved

GotFocus

Posted on 2000-02-16
11
278 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
z = x + y – 1 6 67
Write data from SQL to CSV file - position 1 52
MS Access Search and Replace Using VBA 6 57
vb6 connector to SQL Server 2 34
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now