Solved

Return to invalid textbox after update

Posted on 2013-06-11
7
456 Views
Last Modified: 2013-06-11
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
0
Comment
Question by:paulmcneil
[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
7 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 39238675
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
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 39238683
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
 

Author Comment

by:paulmcneil
ID: 39238749
Thanks very much DatabaseMX. I used the line
SendKeys "{ESC}"
to clear the field after the msg
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 21
ID: 39238926
I would avoid using Sendkeys.  It is problematic.

Try using the  .Undo method of the control
0
 
LVL 75
ID: 39238984
SendKeys "{ESC}" >>>  Me.YourControlName,Undo
0
 
LVL 21
ID: 39239204
What MX said!

Me.YourControlName.Undo
0
 
LVL 75
ID: 39239253
Sorry I did not see that post ...
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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

752 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