Return to invalid textbox after update

I have this code in the AfterUpdate event of a from textbox:

If Not IsNumeric(Me.txtTransactionsProcessed) Then
  MsgBox Me.Controls("lbltxtTransactionsProcessed").Caption & " must be a number.", vbInformation, "Pricing Scorecard"
  Me.txtTransactionsProcessed = Null
End if

I'm simply validating that the user's entry is a number. After the message displays, the cursor moves to the next textbox in the form.

What I want is for the textbox I just validated () to keep the focus after the message is displayed. Thanks
paulmcneilAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
Move your code into the BeforeUpdate event of that textbox, which you can Cancel:

Sub YourContro_BeforeUpdate(Cancel As Integer)
  If Not IsNumeric(Me.txtTransactionsProcessed) Then
    MsgBox Me.Controls("lbltxtTransactionsProcessed").Caption & " must be a number.", vbInformation, "Pricing Scorecard"
  Me.txtTransactionsProcessed = Null
  Cancel = True
End if

End Sub
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
And in moving the code to the BU event, you will need to remove the line:

  Me.txtTransactionsProcessed = Null

You cannot set a Value in the BU event of a Control.

mx
0
 
paulmcneilAuthor Commented:
Thanks very much DatabaseMX. I used the line
SendKeys "{ESC}"
to clear the field after the msg
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
I would avoid using Sendkeys.  It is problematic.

Try using the  .Undo method of the control
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
SendKeys "{ESC}" >>>  Me.YourControlName,Undo
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
What MX said!

Me.YourControlName.Undo
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Sorry I did not see that post ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.