Link to home
Start Free TrialLog in
Avatar of rodneygray
rodneygrayFlag for United States of America

asked on

Before Update Event not firing when moving to unbound field

I have a form designed to allow the user to modify historical data. At the form level, I attached code to the before update. When the user leaves the record, this code is triggered. The code displays a form that captures user id, date, time and shows the user which fields were changed. Then the user is able to accept or discard changes. When the verify form is closed the changes are written/not written based on the users response.  
However, I have run into an issue with the before update event.
  -I change the quantity field from 1 to 5.
  -Then, instead of moving to a different record, I click in an unbound search field I have  provided for the user to search for records.
  -The before update event does not fire when I move to the unbound field
  -If I enter a search term and hit the enter key, my verify screen appears.
  -However, because I am no longer on the record, the update bombs.

My question is: How do I get the before update event to fire when moving to the unbound field.
SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rodneygray

ASKER

The solution you proposed worked great. However, as with many things in life, solving one issue lead to the next, which is related to the solution you proposed.

I placed that code in the "gotfocus" event and it does cause the beforeupdate event to fire. The following code opens the verify form
'Display form and see if user wants to confirm action
            DoCmd.OpenForm strFormName, acNormal, , , , acDialog, strOpenArg
            blnResponse = Forms!frmUpdateConfirm.chkcontinue
            DoCmd.Close acForm, strFormName
            If blnResponse = True Then
            Else
                Cancel = True
                Me.Undo
            End
I carry the old and new data to the verify form with OpenArgs. On the verify screen there are two buttons. One is the continue button. If the operator clicks this button, a record is written to a log file, capturing the user/date/time/old-new data values. blnResponse is set to true
However, if the user cancels the change the blnResponse code is set to False and I run the cancel = true and me.undo events. I set a breakpoint where the blnResponse is being tested for True/False. Value is set to false. The Cancel = True action is executed. The me.undo action is executed. Cursor moves to end. At that point, I get the following error:
Run Time error 2759. The method you tried to invoke on an object failed.
I tried a to return focus to a field in the table to no avail. Any ideas?
let's try this method..
if the record was edited, disable or hide the search textbox ,
in the form's current event, place the codes

me.searchtextbox.visible= not me.dirty
Place code in the current event for the main form. Same error. I am not sure exactly what is happening. Are we getting caught in a "never-neverland" between events firing for the two objects?
upload your db..
Thanks for your help. I am heading home now. That will take about 45 minutes. I will check for your reply when I arrive.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The method suggested by capicorn1 worked with the one exception. In the "beforeupdate" event, I carry the old and new data to a verify form with OpenArgs. On the verify screen there are two buttons. One is the continue button. If the operator clicks this button, a record is written to a log file, capturing the user/date/time/old-new data values. blnResponse is set to true
However, if the user cancels the change the blnResponse code is set to False and I run the cancel = true and me.undo events. At that point, I got the following error:
"Run Time error 2759. The method you tried to invoke on an object failed."
To move forward, I implemented a work around.