Solved

How to effectively cancel LostFocus event in vba

Posted on 2004-09-14
2
2,110 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
[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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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