Solved

Return to invalid textbox after update

Posted on 2013-06-11
7
453 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 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