On Exit Event (1 Viewer)

tlucas

New member
Local time
Yesterday, 19:58
Joined
Jan 6, 2004
Messages
5
Confused...On Exit Event

Hi All,

I'm having a problem with an On Exit event and it doesn't make any sense to me. I have a form with a couple of subforms. I have a control on one of the subforms, and I want to trigger an event (something simple like docmd.save)when I exit that control.

The main form opens just fine, but when I try to enter data into the first field on the main form, I get a Run-time error '2486' (You can't carry out this action at this time.) I hit the debug button, and it is showing me that the error is in the On Exit event for the subform control.

My 1st question is: even if there is a problem with the code I have in the On Exit event for this control, why is this error being triggered when I'm way up at the top of the main form?

Anyone have any ideas?

Thanks in advance,

Tim
 

tlucas

New member
Local time
Yesterday, 19:58
Joined
Jan 6, 2004
Messages
5
Hi again,

I went in cleared all the code from this event, and the rest of the form works fine. So I know it is directly related to what I put down in this On Exit box.

Starting from scratch, I tried to put something simple (or at least I thought it was something simple) in the On Exit event.

Private Sub Material_Exit(Cancel As Integer)
DoCmd.Save
End Sub

This control is in a subform, yet it gives me the error I described as soon as I try to enter anything into the main form. I've checked the tab order, and there are several other fields on the main form that you would have to go through before even getting to the subform, and once you are in the subform there are several more still.

So if this is supposed to be an event-triggered action on a subform, why is Access trying to perform this action (which should be a valid and simple action and not something that should cause an error)) when I try to add data at the top of the main form?

Thanks,

Tim
 

Mile-O

Back once again...
Local time
Today, 03:58
Joined
Dec 10, 2002
Messages
11,316
The purpose of events such as Open, Unload, Exit, BeforeUpdate (ie. those that carry a Cancel parameter) is to allow you to verify data and cancel the update happening to the field bound to the control.

Because you are putting a Save (pssst DoCmd.RunCommand acCmdSaveRecord is probably what you are really after) command into a validation event Access balks - it wants to check the value and test for a response (i.e. allow it or cancel it) while you are trying to force an operation upon it that's out of its scope at that moment in time.

Why you would want to save the record after putting in one piece of information, I'm not going to ask, but you should put the code you want in the AfterUpdate event.
 

Users who are viewing this thread

Top Bottom