• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Need help setting the focus to a control

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
pcalabria
Asked:
pcalabria
2 Solutions
 
Rey Obrero (Capricorn1)Commented:
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
 
mansooralia_yahooCommented:
just put cancel = true no need to focus on anything.
0
 
pcalabriaAuthor Commented:
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now