Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Ignore lostfocus event when a cancel button is pressed

Posted on 2005-03-09
5
Medium Priority
?
683 Views
Last Modified: 2012-05-05
Hi,

I have a nr of fields on my form that I validate via a lostfocus event. But, when I click the cancel-button, I want to exit straight away and ignore those events. Is that possibe?
I can add a line to each lostfocus event like "if combo1.text = "" then do nothing", but I'd like to think there is a more generic way...

Thanks,
  Simon
0
Comment
Question by:shvanwijlen
  • 3
5 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 13499174
Normally you would validate the contents in the Validate event.  Setting the CausesValidation=False for the Cancel button will prevent the Validate event from firing when that button is pressed.
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 13499207
Hi shvanwijlen,
Declare global var that will indicate that cancel button was pressed

Dim bWasCanceled as Boolean


Private Sub btnCancel_Click()
       bWasCanceled   = True

' .... rest of your code if any

End Sub

Private Sub YourControl_LostFocus()

If bWasCanceled Then Exit Sub

'.... your validation code

End sub

Cheers!
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 13499240
BTW
And if there is onnly validation I am absolutelly agree with Erik37.
0
 
LVL 2

Expert Comment

by:RussellMartin
ID: 13499871
go  with Erick37 .
I dont believe michaels approach would work since the lost focus event would in fact invoke before the click event of the cancel button
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 13500390
RussellMartin is right,  forget my post

I am using this technique  sometime but never with LostFocus event,

Sorry
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month15 days, 13 hours left to enroll

580 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