Microsoft Knowledge Base Email Alertz

(208178) - You you try to use the GoToControl method or the SetFocus method in the AfterUpdate event of a control to set focus back the control that is being updated, the GoToControl or SetFocus method will be ignored. For example, the following code, will not...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 208178 - Last Review: June 28, 2004 - Revision: 2.0

ACC2000: GoToControl to Control with Focus in AfterUpdate Ignored

This article was previously published under Q208178
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

On This Page

SYMPTOMS

You you try to use the GoToControl method or the SetFocus method in the AfterUpdate event of a control to set focus back the control that is being updated, the GoToControl or SetFocus method will be ignored. For example, the following code, will not cause the control named MyControl to retain focus once it is updated:
Private Sub MyControl_AfterUpdate()
   DoCmd.GoToControl "MyControl"
End Sub
				
You will see the same behavior when you use the GoToControl action in a Macro.

CAUSE

You cannot set the focus on a form to an object that already has focus.

RESOLUTION

You can get the desired results in one of the following ways:
  • To stop the control focus from changing, regardless of the update status of the control, set Cancel = True in the Exit event of the control.
  • If you want to prevent the changed data from being saved, set Cancel = True in the BeforeUpdate event of the control.
The following example maintains focus on a control, regardless of the update status of that control:
Private Sub MyControl_OnExit(Cancel As Integer)

   Cancel = True

End Sub
				
When you add this code to a control, the only way to move to a different control on the form is by using the pointer.

MORE INFORMATION

Steps to Reproduce Behavior

  1. In the sample database Northwind.mdb, create the following macro named Test1:
       Macro Name   Condition         Action
       ------------------------------------------
       Test1        ([City]="aaaa")   GoToControl
    					
       Test1 Actions
       -------------
       GoToControl
         Control Name: [City]
    					
  2. Open the Customers form in Design view. Set the City control's AfterUpdate property to the Test1 macro.
  3. View the Customers form in Form view.
  4. Type aaaa in the City field and press TAB. Note that the focus moves to the next field in the tab order. However, if you had moved to another control before pressing TAB, the focus would not have changed.

REFERENCES

For more information about the GoToControl action, click Microsoft Access Help on the Help menu, type GoToControl in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

For more information about the GoToControl method, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type GoToControl method in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

APPLIES TO
  • Microsoft Access 2000 Standard Edition
Keywords: 
kbprb kbusage KB208178
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate