Comments inline...
--
Ken Snell
<MS ACCESS MVP>
DJ said:
I have a function which checks to see if there have been changes made to an
unbound form. If a change is made to any field on the form, it calls a
function to mark a boolean variable as false. Everything works great,
except for a few instances, which I have been able to trace back to
setfocus issues (when I remove the setfocus call, it never happens). The
function to set the variable to false is called in the After Update event
of the textboxes, comboboxes, checkboxes. There are no changes made to any
of the values, just a shift from the focus of one object to another (the
setfocus function). Does the setfocus function trigger an After Update
event? If so, why doesn't that happen all the time?
SetFocus itself will not cause an AfterUpdate event to occur for a control.
The AfterUpdate event occurs only after manually editing a value in a
control; if the control itself is dirty (it's still being edited) and you
call a SetFocus action, then the moving of the focus from the control will
cause the control's BeforeUpdate and AfterUpdate events to occur because the
editing process is ending. But otherwise, no, the SetFocus should not create
the problem that you are describing. (Although I don't know what you mean by
"...except in a few instances, which I have been able to trce back to
setfocus issues..." What is failing/not working in those "few instances"?)
Another issue seems to occur with the setfocus event when I set the values
of the controls in VBA. After setting the value of a combobox with a
value from a recordset object, I move on to setting the values of other
objects. At the end, I call the setfocus event of the original combobox
(so that users will be able to start entering changes right away), and the
identity value of the record gets placed into the combobox (no part of my
code does that). I know that the value is applied on the setfocus
function, because it is the last call and when I hit escape afterwards, it
goes back to the original correct value (when the setfocus call was
removed, this problem also went away entirely).
Programmatically writing a value into a control will not cause that
control's AfterUpdate event to occur. Are you saying that the wrong value is
being written into the combobox when the SetFocus is done? I'm sorry, but
the behavior that you describe is just not expected nor reasonable. Unless
you post examples of the code that you're using, it's nearly impossible for
us to troubleshoot what you're seeing. I'm guessing that there is more going
on than you're thinking is occurring.