Solved

Need help setting the focus to a control

Posted on 2011-09-16
3
286 Views
Last Modified: 2012-08-13
Hello,

I use the AfterUpdate Event of a text box to test whether an acceptable input has been entered.

If the entry does not meet my test, I want to delete the entered information, display a msgbox, and then set the focus to the text box again (in the same form), so that a new entry can be made.

I have no trouble with the test and message box, but when I try to set the focus to the text box, the text box that gets the focus is always the next box in the tab sequence.

I've had this issue in the past, and have solved it by setting the focus to the text box before the intended text box, however, this time the text box that I want to set focus on is the first tab and it needs to stay that way.

Does anyone have any ideas?
0
Comment
Question by:pcalabria
[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
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 400 total points
ID: 36549575
normally you use the beforeupdate event for this


private sub text0_beforeUpdate(cancel as integer)

   'if entry does not meet
   'msgbox
   
   cancel=true
   me.text0.setfocus

   exit sub
   end if
end sub
0
 
LVL 2

Assisted Solution

by:mansooralia_yahoo
mansooralia_yahoo earned 100 total points
ID: 36553834
just put cancel = true no need to focus on anything.
0
 

Author Closing Comment

by:pcalabria
ID: 36555910
Fantastic!

I wrote my code without using setfocus,
and it worked fine, so I felt it would be best to leave it out and keep things more simple.

I've never used BeforeUpdate before this,
but I'm sure I will use it often now!

Thanks guys!

PC
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

735 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