Solved

How to effectively cancel LostFocus event in vba

Posted on 2004-09-14
2
1,971 Views
Last Modified: 2012-05-05
Hi,

I have some code that has to be run in the LostFocus event of a textbox.

It checks the contents, and if they're not ok according to some rules, it sets the focus back on the textbox and higlights the text...
If ... Then
        MsgBox "The UAN you entered is not valid, please retype", vbCritical, "Invalid UAN"
        Cancel = True
        Me.B_C.SelStart = 0
        Me.B_C.SelLength = Len(Me.B_C.Value)
End If

That works fine in the BeforeUpdate event where cancel is a parameter, and I understand why it won't work in the LostFocus event, but is there some kind of workaround? ie would it work if I abstracted the code to a module or something along those lines?

Thanks for your help
0
Comment
Question by:shifty_mc
2 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 75 total points
ID: 12052882
<<but is there some kind of workaround?>>

 Use the OnExit event rather then LostFocus.  LostFocus is too late.  Access is already moving to another control.

Jim.
0
 

Author Comment

by:shifty_mc
ID: 12052935
Beautiful stuff - simple as that.

Cheers - points given.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

762 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

22 Experts available now in Live!

Get 1:1 Help Now