AfterUpdate BeforeUpdate onChange

CanWest

Registered User.
Local time
Today, 01:18
Joined
Sep 15, 2006
Messages
272
I will try and keep this simple as the database and form structure are quite complex.

I have the following line of code
Code:
    Forms!pfrm_WSPositionWage!WSPositionID = Forms!pfrm_EditWorkStation!ssfrm_WorkStationPositions.Form!WSPositionID

I need this to work on the AfterUpdate event on a control named Date on the same form. The code is pulling the data from an underlying Form/Subform that is open.

If I put this code on a command button it works great

On any event it does nothing.

I am literally pulling out what little hair I have left on this one. I have done this hundreds of times with no problems.

Any assistance would be greatly appreciated.
 
First you should be using the Before Update event.

Second is that you have a Field in your table named "DATE" This alone could be causing you grief. Date is a reserved word and returns the current Date and Time. You need to change it to DateEntered, Date Processed or anything similar.

I don't know if this will fix your problem but it may help. If it does not help then please post the entire code and wrap those long lines so we can see all at a glance.

BTW Use Copy Paste with your code in order to prevent typos.
 
I have actually tried the BeforeUpdate with the same results.

I have also tried this on several different controls in the form (Not just the Date one) again with the same results.

I did use copy and paste with the code
 
Regardless, you need to fix the Date issue, and it would be nice to see the entire code without scrolling. The entire code is not just one line. Sorry for not explaining properly in my first post to you.
 
I changed the field in question to StartDate

Here is the full code on the BeforeUpdate event on the StartDate control

Code:
Private Sub StartDate_BeforeUpdate(Cancel As Integer)

    Forms!pfrm_WSPositionWage!WSPositionID = Forms!pfrm_EditWorkStation!ssfrm_WorkStationPositions.Form!WSPositionID

End Sub

This is the code on the command button that actually works

Code:
Private Sub cmdSetWsPositionID_Click()
    
    Forms!pfrm_WSPositionWage!WSPositionID = Forms!pfrm_EditWorkStation!ssfrm_WorkStationPositions.Form!WSPositionID

End Sub

Nothing has changed. The button still works but the event triggers do not.

As for why the code is not wrapping so we do not have to scroll I have no idea
 
Is the BeforeUpdate event running and what is the value to be inserted?

Put Stop on the line before Forms!pfrm_WSPositionWage!WSPositionID =.... and check the results in the immediate window.

BTW, do you have
Option Explicit
as the second line of your code module by turning on the option Require Variable Declaration?
 
Is the BeforeUpdate event running and what is the value to be inserted?

I am not sure if it running. I would guess not. The value is a numeric value which is the ID of the underlying form

Put Stop on the line before Forms!pfrm_WSPositionWage!WSPositionID =.... and check the results in the immediate window.

I put stop in but then I am not sure what to do next. I have not done this before

BTW, do you have
Option Explicit
as the second line of your code module by turning on the option Require Variable Declaration?

It is there, but it was typed in rather than turning on an option.
 
Now cause the event to happen.

The VBA will stop at the Stop line.

Then in the immediate window at the bottom of the VB Editor (if it's not showing, press Control + G), type
? Forms!pfrm_EditWorkStation!ssfrm_WorkStationPositions.Form!WSPositionID
to show what you're trying to put in your text box
 
Ok I may be having a brain fart or something but I have put Stop where you said. I was expecting a dialogue box to pop up asking me to go to debug or something like that when I changed the value in StartDate. It did not so I was not in the VBA Editor and could not go to the immediate window. Am I missing something?
 
Instead try a message box before and after the line in question.
 
BeforeUpdate and AfterUpdate Events of the control are not going to do anythng unless you actually Update the control and move out of it. OnChange will fire every time you enter a character but you hve to enter something.

Try the OnEnter Event. This should fire when you click in the control.

BTW Instead of muddling around adding Stop lines and retrieving values using the Immediate Window and Message Boxes, show the Locals Window and pause execution using Break Points.

The Locals Window shows everything about the current state.
 
BeforeUpdate and AfterUpdate Events of the control are not going to do anythng unless you actually Update the control and move out of it.

I put a stop in front of the line of code in question. Then I entered a date in that field and moved out of the field. Nothing happened. I have this very same line of code on a command button and it worked perfectly. I just can not get it to execute on the BeforeUpdate or the AfterUpdate.

When I put the stop in front of that line of code I expected something to happen when I updated the field. Absolutely nothing happened.
 
startdate beforeupdate WILL ONLY fire if you change the value by entering data into a control. changing the value in code will not make the event fire.

so what are you doing that you think ought ot make this event happen?
 
startdate beforeupdate WILL ONLY fire if you change the value by entering data into a control. changing the value in code will not make the event fire.

so what are you doing that you think ought ot make this event happen?

Sorry I was not clear. StartDate is the control (field) that I have set the BeforeUpdate code on.

I have entered a date in the StartDate control (not in code) but in form view and then moved to the next field. The code does not do anything.
 
I have had the odd occasion when the code in an event procedure did not execute on the event.

In design mode, select the double click event for the control and move the code to that event. If the code executes, delete the now empty BeforeUpdate procedure and recreate it by going to the Events tab on the Properties for the control.
 
In design view look at your properties box.

Select then control then go to Events tab, then check that the Before Update Event has "EVENT PROCEDURE" selected.

If not add it.

In any case go to the code by selecting the three dots on the right.

This must take you to your code.
 
rain's point is important

if you have copied code, or renamed a control, access will no longer link the code to the event. the code will be orphan code that may never run. checking the actual event property will show whether this is the case.
 
rain's point is important

if you have copied code, or renamed a control, access will no longer link the code to the event. the code will be orphan code that may never run. checking the actual event property will show whether this is the case.

Dave

I don't know why we did not think of this earlier.

I woke in the middle of the night and went, Ahhhhhhhhhhhhhhhhhh
 
CanWest

Just a quick not to say that you need to be careful as to which event you use.

Some events may make changes even when you don't want them to.
 

Users who are viewing this thread

Back
Top Bottom