Colour won't change when form opened

T

Troy

Hi!

I have a form with a subform on it. On the subform I have totals on the form
footer. I have a subprocedure on the main form and the subform that checks
the totals on the sub form against field values on the main form changing
the subform totals textbox background colour to green if valid or red if
invalid. I have a command button on the main form and on the subform that
executes each respective sub procedure. I also executed the sub procedure
from the OnActivate Event and the Current Event for the main form.

The problem is that when I open the form the subprocedure runs but the
colours are wrong. If I set a break point in the subprocedure and open the
form and step through the code the colours are correct. If I run the
subprocedure from the command buttons the colours are correct.

It's as if the data in the total fields or the main form fields(the data
that is compared in the subprocedure) is not yet there as the form is
opened.

An insight into why this happens and a solution would be appreciated.

Thanks

Troy
 
T

tina

when you open a form that has a subform on it, the subform loads *before*
the main form. suggest you try putting your "change colors" procedure on the
main form's Current event, or perhaps the main form's Load event, rather
than on form events in the subform.

btw, an easy way to see in what order event fire is to put a message box in
each procedure (that you're wanting to check), with the name of the form and
the name of the event. then as each event fires, its' message box pops up
and tells you exactly what's happening. example:

Private Sub Form_Current()

MsgBox Me.Name & " Current"

End Sub

Private Sub Form_Load()

MsgBox Me.Name & " Load"

End Sub

Private Sub Form_Open(Cancel As Integer)

MsgBox Me.Name & " Open"

End Sub

i put the above procedures in my main form, and also in my subform - and
then opened the main form in form view. as each message box opened, it
showed me the exact order of events.

hth
 
T

Troy

Hi Tina

The sub procedure is in the On Current Event on the main form, I have also
just tried it in the Load Event with no luck. I have also had it in the
Activate Event with no luck. I have also tried it in these Event on the Sub
form with no luck.

Regards

Troy
 
T

tina

hmm, all i can suggest is that you add message boxes to the various events
to show the values in the pertinent controls at the time those events fire
during a runtime test - so you can see what values are present when the code
runs. if you can figure out *when* the correct values appear in the
pertinent controls, you'll have a starting point to figure out where and how
you need to intervene to fix the sequence of events - or more specific
detail about what's happening, to include in a new post for help. good luck.

hth
 

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