Don't want Form Load event to trigger a Form Current procedure - Access2k

L

Leonard Priestley

I have created a form which includes a subform. Data appearing in the
subform is summarised, and the results are passed to the main form, where
they control a thermometer display which I want to be able to change, to
reflect changes in the subform data.

The code to update the thermometer display is a public procedure in a
module. I have used the Form Current event to call the update routine so
that the thermometer display is updated when the form displays the next
record, or when the subform is altered. Once the database is open and
running, this works fine.

My problem is that when the form is loaded, it is apparently followed by a
Form Current event, calling the update routine, and this produces an error
message, because the update routine is referring to a textbox on the form,
which is not properly open yet.

It seems that I need to suppress the Form Current event at startup, or
introduce a delay until the form has been able to open. I wonder if anyone
can show me how to do this, or suggest another approach. It's probably
obvious that I'm still in the beginner class.

Leonard Priestley
 
A

AliKwok

Hi

You can't suppress an event - it either occurs or it doesn't - but you can
handle the exception (being the un-initialised text box) as part of your
event-handling routine.

In this case your code would simply test the state of your text box, and
procede in the normal way if it passes, say:

(Within Sub myForm_Current)

If myTextBox.Value >0 then
myUpdateRoutine
Else
'Do nothing because text box not initialised
End If

Be sure to use indenting to make code easier to read.
Hope this helps

Ali Kwok
 
D

Daniel Doyle

Hello Leonard, when you say that the ' update routine is referring to a
textbox on the form, which is not properly open yet' what do you mean by not
properly open? Does it not have a value or a value that you don't want to
use?
Is it possible that the temperature could be below 0?

Dan Doyle.
 
F

fredg

I have created a form which includes a subform. Data appearing in the
subform is summarised, and the results are passed to the main form, where
they control a thermometer display which I want to be able to change, to
reflect changes in the subform data.

The code to update the thermometer display is a public procedure in a
module. I have used the Form Current event to call the update routine so
that the thermometer display is updated when the form displays the next
record, or when the subform is altered. Once the database is open and
running, this works fine.

My problem is that when the form is loaded, it is apparently followed by a
Form Current event, calling the update routine, and this produces an error
message, because the update routine is referring to a textbox on the form,
which is not properly open yet.

It seems that I need to suppress the Form Current event at startup, or
introduce a delay until the form has been able to open. I wonder if anyone
can show me how to do this, or suggest another approach. It's probably
obvious that I'm still in the beginner class.

Leonard Priestley

Dim a variable up in the declarations section of the code.

Option Explicit
Dim intSkipMe as Integer

then code the Load event
intSkipMe = 1

Next code the Form's Current event:

If intSkipMe = 1 Then
intSkipMe = 0
Exit Sub
Else
' Do the Current event stuff
End If
 
M

Marshall Barton

Leonard said:
I have created a form which includes a subform. Data appearing in the
subform is summarised, and the results are passed to the main form, where
they control a thermometer display which I want to be able to change, to
reflect changes in the subform data.

The code to update the thermometer display is a public procedure in a
module. I have used the Form Current event to call the update routine so
that the thermometer display is updated when the form displays the next
record, or when the subform is altered. Once the database is open and
running, this works fine.

My problem is that when the form is loaded, it is apparently followed by a
Form Current event, calling the update routine, and this produces an error
message, because the update routine is referring to a textbox on the form,
which is not properly open yet.

It seems that I need to suppress the Form Current event at startup, or
introduce a delay until the form has been able to open. I wonder if anyone
can show me how to do this, or suggest another approach. It's probably
obvious that I'm still in the beginner class.


Try testing a main form text box before calling your
procedure:

'subform's Current event
If IsError(Parent.textbox) Then Exit Sub
'call your procedure
 
L

Leonard Priestley

Daniel Doyle,

Thank you for your interest. I think I may already have a solution, but I
will try to answer your question anyway.

My main form is called frmEquipmentType. The subform it hosts is called
frmEquipmentItem_sub. The subform has a checkbox which can be ticked when
an item of equipment has been tested. I want the action of ticking the
checkbox to be reflected in a bar display on the main form. I have done
this by making a public sub called DoBar, which picks up information from
the subform re: total number of items tested, and uses it to control the bar
on the main form. Public Sub DoBar() is what I meant when I mentioned an
update routine.

The sub procedure includes two lines of code which refer to the main form,
like this:
Forms![frmEquipmentType].rctIndicator.Height = 5295 -
(5295*Percentage)/100

When the database is open and operating, this code works fine. But at
startup, I get a message saying:
"Can't find form frmEquipmentType referred to in a macro or Visual Basic
Code"

I am assuming that the reason the form cannot be found is that it has not
yet opened. In electronics I would think of this as a "race" condition,
where two things are so closely connected that they are trying to happen
simultaneously. Poor design on my part, and maybe I should rethink the
whole business, but two other emails on the subject suggest that I may be
able to do a Form Load without running DoBar. We'll see.

Thanks again. The prompt, generous response I receive to my pleas for help
always impresses me. There are some very nice people out there.

Query temperature below 0?

Leonard
 

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