Solved

Return to invalid textbox after update

Posted on 2013-06-11
7
412 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 - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now