Solved

Return to invalid textbox after update

Posted on 2013-06-11
7
445 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
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

792 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