Solved

Need help setting the focus to a control

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

Accepted Solution

by:
Rey Obrero earned 400 total points
Comment Utility
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
Comment Utility
just put cancel = true no need to focus on anything.
0
 

Author Closing Comment

by:pcalabria
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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

9 Experts available now in Live!

Get 1:1 Help Now