Order of Events Question

D

David

I am trying to make a button visible based upon a calculated field which
involves more than two DLookup functions and several other calculated fields.

If a button's visible status is based upon a field in the form's underlying
query, the visible and invisible status works great in the current event.

When it is based on a calculated field, the current event is too soon, the
GotFocus event is too late, and I can't find any other event that will wait
for the calculations to be complete before determining the visible status.

Any suggestions?
 
K

Ken Snell [MVP]

Try the Enter event for the button. You can cancel that event if your code
identifies that the button should not be visible.
 
D

David

Yes... I keep reading about the Enter event but I can't locate it on the
button event list. Where do I look for it?
 
K

Ken Snell [MVP]

Open the form in design view. Click on the command button. Click on
Properties icon on toolbar. Click on Event tab. Should be the first property
in the list on that tab.
 
D

David

Ken,
I thought the visible status needed to be set in the form property, not in
the command button property. That is why I could never find the Enter event
since there isn't one on the form property.

I tried your suggestion... the button is visible at all times and when I
click the button I get the error "cannot hide object that has the focus."

Am I doing something wrong?
 
D

David

As a further step, I selected an object to receive the focus when the form
opens and placed the code to hide or show the button under its Enter event
and it works great when the form opens.

However, when the record changes, it fails to change the visible status. The
object still receives the focus but nothing changes.

I think we're on the right track but gotta tweak this a little more...
 
K

Ken Snell [MVP]

Sometimes I think my brain cells are far behind my fingers when typing
answers.....

You're correct, of course, that you can't make a button invisible when it
has the focus. What you can do in that OnEnter property's event procedure is
to reset the focus just before you make the button invisible.

The "solution" of using the Enter event means that the button will always be
visible until you click on it. I state upfront that I would not want to use
this event for what you're doing. Normally I would use the Current event for
what you're doing...and I might, because you say the calculated fields are
taking too long, repeat the calculations in the Current event's procedure
code in order to do this, rather than rely on the controls' Control Source
to give me the value that I want to use. Can you do this in your code?

Also, if you use the Enter event, you'll need to use the Current event to
make the button visible again for the "next" record that you visit.
--

Ken Snell
<MS ACCESS MVP>
 

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