On Current events keep executing over and over again for the same open forms

  • Thread starter Bill Reed via AccessMonster.com
  • Start date
B

Bill Reed via AccessMonster.com

I have a startup form which sets some parameters and then opens the main
form. The main form contains 2 subforms which in turn contain 3 subforms
each. The 2 subforms are on tabs in a tab control on the mainform. Their 3
subforms are nested in each of the 2 subforms. (Confusing, isn't it!?)
In addition, there are 2 pop up forms that load with the main form.

I can live with the on current events executing over and over again for the
same forms, but it's kind of messy and I'd really like to minimize it and
hasten the process of opening the main form. I imagine I'm not the 1st to
come across this problem so I'm hoping there's a "rule of thumb" or some
piece of code to use during the on current event of the main form and
subsequent forms that will limit the firing of these events to when I want
them to fire.

Thanks
 
R

Rick B

ON CURRENT fires when you move from one record to another.

What are you trying to accomplish?
 
B

Bill Reed via AccessMonster.com

Once the app is open and running, there are events that have to run On
Current that effect the data in subforms and popups which in turn have to
be requeried to display the data corresponding to the new data in the
current record. Unfortunately, when the main form 1st loads, the On Load
event causes those On Current events to start firing off. In the case of a
certain popup form, those current events fire off about 6 times during the
load process. When a form is requeried in the normal operation of the app,
it's dependent subforms and popus are requeried, which fires their current
events, which in turn loop back to other forms and the whole thing results
in the same forms being requeried multiple times and current events firing
multiple times. Is there any way to streamline the process? I can't seem to
get a handle on logic that would force the current events to only fire when
I want them to.
 
K

Ken Ismert

Access is unique among Office products in that you can turn events off
and on. The simple (but not elegant) mechanism is the existance or
absence of a predefined string in the form's On<event> property.

Sample code:

(in a standard module)
Public Const pcEventStub As String = "[Event Procedure]"

(in your form)
Private Sub EventsRehook()
Me.OnCurrent = pcEventStub
End Sub

Private Sub EventsUnhook()
Me.OnCurrent = ""
End Sub

Of course, you must decide when and how to turn your OnCurrent on and
off.

-Ken
 
B

Bill Reed via AccessMonster.com

I don't doubt your word ;-), but I'm baffled as to how this code works.
Please help me understand what these few simple lines of code are doing.

Thanks

PS.

Is there any place on this forum to post a contribution? I have a very
simple form that I find indispensable in my programming efforts, which I
would like to share with the community. It isn't much, but I get so much
help here I'd like to give something back. It's just a form that displays
the table links along with a date stamp and complete path and name of the
current db. To an old hand like yourself it might not be very impressive,
but it's the kind of thing I wish I had all along. It prevents me from
making changes to the wrong front end, while permitting a complete view of
the path to linked tables. With it, I can be certain that I'm not making
changes to live data.
 
K

Ken Ismert

Well, when you open your form in design view, and click on the Event
tab in form properties, you will notice the text [Event Procedure] next
to the events you have enabled in code. When you click on the [...]
button next to such an event, you will be taken to your event handler,
such as:

Private Sub Form_Current()
' Your event code here
End Sub

That much is obvious. What maybe isn't so obvious is that the On
Current line in the Event tab of form properties corresponds to an
actual form property, OnCurrent. For the code above to be called,
OnCurrent must have a value of "[Event Procedure]". If that exact
string isn't in the OnCurrent property, the event handler will never be
called.

This gives you a crude but effective way of turning all Access form and
control events on and off, using the code in my previous post.

In a fair number of my forms, I turn off the Current event at critical
times (loading, adding and finding a new record, etc.). I then turn it
on when I want its normal function. So, this approach can work.

Still, a word of warning: don't overuse this feature. Events are
unpredictable, and have a habit of firing at the darndest times. Expect
to spend time debugging your form to get this to work properly.

-Ken

ps. This forum doesn't have a contribution mechanism, as far as I know.
Other forums, like AccessD, http://www.databaseadvisors.com , and
AccessL (Roger's Access Library), http://www.rogersaccesslibrary.com/ ,
will allow you to post contributions.
 

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