473,414 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Should DoCmd.CancelEvent inside an Exit event procedure cancel ensuing events?

MLH
I have a form, frmUSPSReturnReceipts, with a control named
NotExpectingGreenTickets. The control's Exit event procedure
follows:

Private Sub NotExpectingGreenTickets_Exit(Cancel As Integer)
If IsNull(Me!NotExpectingGreenTickets) Then
DoCmd.CancelEvent
Exit Sub
End If
End Sub

I slipped in a MsgBox statement that ensures me DoCmd.CancelEvent
runs. I thought cancelling this event meant exactly that the Exit
event would, in fact, be canceled. It doesn't seem logical that other
events normally occurring after an Exit event. But they do. Is that
what was intended? If so, what exactly is the point of canceling an
event. The Exit Sub statement prevents further code in the procedure
from running. I thought CancelEvent was supposed to do something
more.
Jan 22 '07 #1
6 7699
What happens if you replace:
DoCmd.CancelEvent
with:
Cancel = True

If that doesn't work, what other events are you talking about that still
fire? I would not expect the GotFocus of the next control to fire if Exit
was cancelled, but other events (such as those of the Form) might still
fire.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.netwrote in message
news:6k********************************@4ax.com...
>I have a form, frmUSPSReturnReceipts, with a control named
NotExpectingGreenTickets. The control's Exit event procedure
follows:

Private Sub NotExpectingGreenTickets_Exit(Cancel As Integer)
If IsNull(Me!NotExpectingGreenTickets) Then
DoCmd.CancelEvent
Exit Sub
End If
End Sub

I slipped in a MsgBox statement that ensures me DoCmd.CancelEvent
runs. I thought cancelling this event meant exactly that the Exit
event would, in fact, be canceled. It doesn't seem logical that other
events normally occurring after an Exit event. But they do. Is that
what was intended? If so, what exactly is the point of canceling an
event. The Exit Sub statement prevents further code in the procedure
from running. I thought CancelEvent was supposed to do something
more.
Jan 22 '07 #2
MLH
Responses embedded...

On Mon, 22 Jan 2007 12:31:03 +0900, "Allen Browne"
<Al*********@SeeSig.Invalidwrote:
>What happens if you replace:
DoCmd.CancelEvent
with:
Cancel = True
Pretty much the same thing happens. I get confirmation msg that
the Exit event was canceled. Then the LostFocus event for same
control fires anyway.
>
If that doesn't work, what other events are you talking about that still
fire?
LostFocus event for the same control
>I would not expect the GotFocus of the next control to fire if Exit
was cancelled, but other events (such as those of the Form) might still
fire.
Jan 22 '07 #3
MLH <CR**@NorthState.netwrote in news:q2a9r2drujkriqboqd9fkhucg6588o7t28@
4ax.com:
Responses embedded...

On Mon, 22 Jan 2007 12:31:03 +0900, "Allen Browne"
<Al*********@SeeSig.Invalidwrote:
>>What happens if you replace:
DoCmd.CancelEvent
with:
Cancel = True
Pretty much the same thing happens. I get confirmation msg that
the Exit event was canceled. Then the LostFocus event for same
control fires anyway.
>>
If that doesn't work, what other events are you talking about that still
fire?
LostFocus event for the same control
>>I would not expect the GotFocus of the next control to fire if Exit
was cancelled, but other events (such as those of the Form) might still
fire.
The exit event occurs only when the focus moves from the control to another
control on the same form. The lostFocus event occurs when the control loses
the focus for whatever reason.

So, perhaps the exit event doesn't occur in the cases when the lost focus
event fires but "shouldn't". You could tell by putting a temporary MsgBox
into your Exit Event Code.

Does the exit sub serve any purpose?

Have you considered removing the code and setting the required property of
the underlying field to true? Then Access will handle everything for you.
Jan 22 '07 #4
Okay, that's not intuitive, is it.

Access does indeed fire the LostFocus event of the control, even if the Exit
event if cancelled, but only the first time you try to get out of the
control. If it's already been cancelled previously, LostFocus doesn't fire
again.

Seems like it's been like that for quite some time. Access 97 has that
behavior, and 2007 is the same.

While it's not really what you expect, it should not be an insurmountable
problem. At worst, you would need to create a module-level variable. If you
cancel the Exit, set your variable to True. Check it in LostFocus, and take
no action of the module-level boolean is true. Don't forget to reset it in
LostFocus.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.netwrote in message
news:q2********************************@4ax.com...
Responses embedded...

On Mon, 22 Jan 2007 12:31:03 +0900, "Allen Browne"
<Al*********@SeeSig.Invalidwrote:
>>What happens if you replace:
DoCmd.CancelEvent
with:
Cancel = True
Pretty much the same thing happens. I get confirmation msg that
the Exit event was canceled. Then the LostFocus event for same
control fires anyway.
>>
If that doesn't work, what other events are you talking about that still
fire?
LostFocus event for the same control
>>I would not expect the GotFocus of the next control to fire if Exit
was cancelled, but other events (such as those of the Form) might still
fire.
Jan 22 '07 #5
MLH
Yep. That sounds like a plan. Many thx for the work-a-round.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mon, 22 Jan 2007 21:40:20 +0900, "Allen Browne"
<Al*********@SeeSig.Invalidwrote:
>Okay, that's not intuitive, is it.

Access does indeed fire the LostFocus event of the control, even if the Exit
event if cancelled, but only the first time you try to get out of the
control. If it's already been cancelled previously, LostFocus doesn't fire
again.

Seems like it's been like that for quite some time. Access 97 has that
behavior, and 2007 is the same.

While it's not really what you expect, it should not be an insurmountable
problem. At worst, you would need to create a module-level variable. If you
cancel the Exit, set your variable to True. Check it in LostFocus, and take
no action of the module-level boolean is true. Don't forget to reset it in
LostFocus.
Jan 23 '07 #6
MLH
Good suggestion on the Required property. The control is an unbound
combo box. Perhaps setting its ValidationRule property to Not Null or
something along those lines will mirror your intended effect.

<snip>
>
The exit event occurs only when the focus moves from the control to another
control on the same form. The lostFocus event occurs when the control loses
the focus for whatever reason.

So, perhaps the exit event doesn't occur in the cases when the lost focus
event fires but "shouldn't". You could tell by putting a temporary MsgBox
into your Exit Event Code.
I checked that possibility, embedding a MsgBox alert in there. For
certain, the Exit event is firing.
>
Does the exit sub serve any purpose?
Not really. I was grasping at straws there.
>
Have you considered removing the code and setting the required property of
the underlying field to true? Then Access will handle everything for you.
Jan 23 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jim | last post by:
I am using Access 97 on a PC running Windows NT 4.0 SP6a. I have some code (shown below) intended to add a set of records to one table (tblGradeProps) when a new record is created in another...
1
by: Dalan | last post by:
Although I have used the code below to suppress the DoCmd cancel action message from appearing on lots of other actions such as preview and print, I have not been able to get to work on a...
10
by: Nathan Sokalski | last post by:
I have a DataList control with an EditTemplate. Three of the controls in this template include a Calendar, a Button with CommandName="update", and a Button with CommandName="cancel". Whenever I...
2
by: Just Me | last post by:
I've seen this in example code: Private Sub Studio_Closing(ByVal sender A..snip.. Handles MyBase.Closing If e.Cancel Then Exit Sub ....snip... It would make sense if Windows keeps doing...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
2
by: jsimons | last post by:
If the user accidentally clicks the X close button I'm using the following code in the form unload event to stop them from accidentally quitting Access. Private Sub Form_Unload(Cancel As...
1
by: KShapiro | last post by:
Hi All, I am trying to assist my wife, by making a simple menu system for the website. The web page is a .php4 file and does an include of the navigation file. Before it includes that file at...
4
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by...
7
by: surferj | last post by:
Hello, I am trying to run a macro in that was created in an earlier version of access but getting an error message when i try to run it in 2007. The error occurs on the DoCmd.RunMacro...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.