why does some code run first and other code not at all?

A

ArielZusya

I'm struggling with a runtime issue (at least I think that's how best to
describe this) in Access 2007. I've got code that causes, when a particular
form is loaded, a custom ribbon to become visible. I've got other code that
causes a particular tab on the ribbon to gain focus (thanks to Tony Jollans).
The trouble is, if the ribbon is not visible and is made visible, the code
switching focus to that ribbon doesn't seem to do anything (it runs without
error but it doesn't result in the newly visible tab to have the focus). On
the other hand, if the tab is already visible, the switch focus sub routine
works and the focus changes. Any idea why this would be?

In detail, what I'm doing is:
1) loading a form
2) in the on load I've got code that checks a global Boolean to see if the
ribbon is visible
3) if it is I don't change it but if it isn't I set the Boolean to true and
then reinitialize the ribbon using invalidate
4) I then check to see what state my data is in and if certain data exists I
have code that uses the invalidate and Booleans to cause particular buttons
and groups on the ribbon to become visible and invisible
5) I call code that switches the focus to the tab of my choosing

It seems that if the system does anything at steps 3 and 4 then it doesn't
do anything at step 5. I have this weird feeling that, when it does do
something at steps 3 and/or 4 it may be switching focus to the tab of my
choosing at step 5 but then switching back to the tab furthest to the left.
At any rate, if someone can tell me how to solve this problem, I'd be
grateful! Thanks for your help!

Ariel
 
J

John Spencer

Try inserting a call to DoEvents in your code immediately after you make
the ribbon visible.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
A

ArielZusya

Wow... that did it... so... can you tell me why that worked? I'm not even
using the returned value of the number of forms open. Is it because it was
slowed down or because it was reflecting on the fact that the form is now
open or what? I'd love to know how that worked. Thanks for your help!

Ariel
 
P

PieterLinden via AccessMonster.com

ArielZusya said:
Wow... that did it... so... can you tell me why that worked? I'm not even
using the returned value of the number of forms open. Is it because it was
slowed down or because it was reflecting on the fact that the form is now
open or what? I'd love to know how that worked. Thanks for your help!

Ariel
Try inserting a call to DoEvents in your code immediately after you make
the ribbon visible.
[quoted text clipped - 35 lines]

DoEvents basically makes all the events before it to finish before going on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top