Solved

Need help setting the focus to a control

Posted on 2011-09-16
3
280 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
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views 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 Access…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

832 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