Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When changing color of mainform another form opens :(

Status
Not open for further replies.

HydraNL

Technical User
May 9, 2005
74
0
0
NL
Hi,

In my App it is possible for the user to change the entire color of the App. The strange thing is when they choose a color another form opens.

Code:
Private Sub mnuYellow_Click()
   Call modColor.Yellow
   lblColor.Caption = 1  'I need this for the other forms.
                         'When they open they get the same 
                         'skin as the mainForm
End sub[\code]
[code]Private Sub lblColor_Change()
   If frm2.Enabeld = True Then 
      frm2.lblColor.Caption = frmMain.lblColor.Caption
   End If

   If frm3.Enabeld = True Then
      frm3.lblColor.Caption = frmMain.lblColor.Caption
   End If
End Sub[\code]
The strange thing is when I click the "Yellow" frm2 seems to get loaded, but dus not appear, but frm3 opens. But with the correct color.

Anyone knows what I'm doing wrong?
 
It could be that checking the enabled property causes the form to load. You could check to see if the form is loaded before setting the color by examining the forms.

Replace
Code:
   If frm3.Enabeld = True Then
      frm3.lblColor.Caption = frmMain.lblColor.Caption
   End If

With

Code:
Dim frmTemp as Form

For Each frmTemp in Forms
  If frmTemp.Name = "frm3" then
    frmTemp.lblColor.Caption = frmMain.lblColor.Caption
  End If
Next

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
gmmastros is right. Enabling the form causes the activate event to fire and i think also the load.
 
Thanks for the replies.

Code:
Private Sub lblColor_Change()
Dim frmTemp As Form

    For Each frmTemp In Forms   ' The name of the MainForm
                                ' = frmZoeken
        'frmGemeente is name of the 2nd Form
        If frmTemp.Name = "frmGemeente" Then
            frmTemp.lblColor.Caption = frmZoeken.lblColor.Caption
        End If
    Next

    For Each frmTemp In Forms
        'frmCollega is name of the 3rd Form
        If frmTemp.Name = "frmCollega" Then
            frmTemp.lblColor.Caption = frmZoeken.lblColor.Caption
        End If
    Next
End Sub
The label on either of the forms don't get the value of the mainForm (frmZoeken). Now nothing gets executed, cause of the lblColor.Caption doesn't get a value.
 
It could be a typo, or a case sensitive issue. Try adding the following lines of code.

For Each frmTemp In Forms
Debug.Print frmTemp.Name
Next

Make sure you set a break point and then step through the code. The name of each form should appear in the debug window.

Hope this helps.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
I suspect that problem lies with the way that you are referencing frmZoeken.

as a test try
Code:
            frmTemp.lblColor.Caption = vbRed
instead of
Code:
            frmTemp.lblColor.Caption = frmZoeken.lblColor.Caption
I reckon that by referenceing frmZoeken you are creating another instance of it.
i.e.

new project add 2 forms (form1 and form2) put a button on form1 and past the code below in to it
Code:
dim f as form2

set f = new form2

f.caption = "My Caption"

debug.print f.caption
debug.print form2.caption



Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Thank you both...
The Debug saiz: frmTemp=frmzoeken.. further nothing.

I waill check it out later. Thanks till so far.
 
My understanding of when form events are fired:

Init: first time form is referenced in the app. The statement "set myForm = New Form1" will cause Form1's init event to be fired, and only the init event.

Load: Only if not already loaded. 1. when referencing a property or calling a method. 2. When executing Load statement. 3. On form.show method, if form is not previously loaded via 1 or 2 above.

Activate: Only when a procedure ends with a form being shown, when no forms were shown prior to executing the procedure. N. B.: Activate is NOT called when switching focus from one form to another.

Deactivate: whenever focus leaves a form.

Unload: when a form is unloaded. This can happen either by specifically unloading a form, or if a form is loaded via a variable, setting that variable to nothing will also unload the form.

Terminate: when an application ends, all loaded forms are terminated. Also when a variable referencing a not otherwise loaded form is set to nothing, its form is terminated.

This probably isn't perfect. If you're interested, just put a msgbox in each event you want to know about and play around with different ways of referencing a form.

HTH

Bob
 
Bob,
In my version (VB6) the Form Activate event is fired every time that the form gets focus from within the app, but not when it gets focus from another app.
Similarly Deactivate is only fired when the form loses focus to another form in the same app, not when another app gets focus.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
That's interesting, John. I always thought that it did the same, but those are the results I got from marking all of the events with a msgbox and doing various load and show commands and whatnot. I'm using VB6 here too (working on a short term contract). I'll try it again at home.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top