setfocus issues

  • Thread starter Thread starter DJ
  • Start date Start date
D

DJ

I am having issues using the setfocus method on various forms with
comboboxes. Does anyone know of any events that fire on a setfocus call?
VBA is doing some weird things.

Thanks for your help.

DJ
 
The LostFocus and Exit events of the control that is losing the focus will
occur, and the Enter and GotFocus events of the control receiving the focus
will occur.
 
Thanks for the reply Ken. At the moment I have no vba code for any of those
events. Is there something else that Access might be doing behind the
scene? I do have vba code for onclick events of the aforementioned
comboboxes on the form. Would that cause any issues?

Thanks,

DJ
 
Please provide some details of what is happening... your original post just
mentioned "difficulties"... please tell us more.
 
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?

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).

Any insight you can provide into the rational of these abnormalities would
be appreciated.

Thanks,

DJ
 
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.
 
Back
Top