Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If I programmically import a UserForm with
Application.VBE.ActiveVBProject.VBComponents.Impor t ("UserForm.frm") and show it with Set UserForm = VBA.UserForms.Add("UserForm") UserForm.Show then change any control property (in my case, UserForm.Label1.Backcolor) in a module (rather than from within the UserForm code), the UserForm initialize event is triggered on the first call to the module (not on subsequent calls). Also, the control property is changed (Backcolor), but the screendisplay doesn't reflect this (Application.ScreenUpdating=False is not used). As expected, all control property changes done within the UserForm code behave properly. This is for XL97 on Windows 98 Thanks for any help. Dave G UserForm Code /// works as expected Private Sub Label2_Click() Static lb2Cnt As Integer Dim IsOdd As Boolean lb2Cnt = lb2Cnt + 1 If lb2Cnt / 2 = Int(lb2Cnt / 2) Then IsOdd = False Else IsOdd = True If IsOdd Then UserForm.Label2.BackColor = &HFF& Else UserForm.Label2.BackColor = &HFF00& End Sub ///doesn't work even though the same code (expect use Label1) as above is in the Call routine Private Sub Label1_Click() 'change via Call Static lb1Cnt As Integer Dim IsOdd As Boolean lb1Cnt = lb1Cnt + 1 If lb1Cnt / 2 = Int(lb1Cnt / 2) Then IsOdd = False Else IsOdd = True Call TestViaCall(IsOdd) End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
hi,
guessing here but you may have the cart in front of the horse. change properties THEN show the form. sometimes the syntax is correct but in the wrong place causing out of correct sequence executions. Regards FSt1 " wrote: If I programmically import a UserForm with Application.VBE.ActiveVBProject.VBComponents.Impor t ("UserForm.frm") and show it with Set UserForm = VBA.UserForms.Add("UserForm") UserForm.Show then change any control property (in my case, UserForm.Label1.Backcolor) in a module (rather than from within the UserForm code), the UserForm initialize event is triggered on the first call to the module (not on subsequent calls). Also, the control property is changed (Backcolor), but the screendisplay doesn't reflect this (Application.ScreenUpdating=False is not used). As expected, all control property changes done within the UserForm code behave properly. This is for XL97 on Windows 98 Thanks for any help. Dave G UserForm Code /// works as expected Private Sub Label2_Click() Static lb2Cnt As Integer Dim IsOdd As Boolean lb2Cnt = lb2Cnt + 1 If lb2Cnt / 2 = Int(lb2Cnt / 2) Then IsOdd = False Else IsOdd = True If IsOdd Then UserForm.Label2.BackColor = &HFF& Else UserForm.Label2.BackColor = &HFF00& End Sub ///doesn't work even though the same code (expect use Label1) as above is in the Call routine Private Sub Label1_Click() 'change via Call Static lb1Cnt As Integer Dim IsOdd As Boolean lb1Cnt = lb1Cnt + 1 If lb1Cnt / 2 = Int(lb1Cnt / 2) Then IsOdd = False Else IsOdd = True Call TestViaCall(IsOdd) End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Jun 12, 8:53 pm, FSt1 wrote:
hi, guessing here but you may have the cart in front of the horse. change properties THEN show the form. sometimes the syntax is correct but in the wrong place causing out of correct sequence executions. Regards FSt1 " wrote: If I programmically import a UserForm with Application.VBE.ActiveVBProject.VBComponents.Impor t ("UserForm.frm") and show it with Set UserForm = VBA.UserForms.Add("UserForm") UserForm.Show then change any control property (in my case, UserForm.Label1.Backcolor) in a module (rather than from within the UserForm code), the UserForm initialize event is triggered on the first call to the module (not on subsequent calls). Also, the control property is changed (Backcolor), but the screendisplay doesn't reflect this (Application.ScreenUpdating=False is not used). As expected, all control property changes done within the UserForm code behave properly. This is for XL97 on Windows 98 Thanks for any help. Dave G UserForm Code /// works as expected Private Sub Label2_Click() Static lb2Cnt As Integer Dim IsOdd As Boolean lb2Cnt = lb2Cnt + 1 If lb2Cnt / 2 = Int(lb2Cnt / 2) Then IsOdd = False Else IsOdd = True If IsOdd Then UserForm.Label2.BackColor = &HFF& Else UserForm.Label2.BackColor = &HFF00& End Sub ///doesn't work even though the same code (expect use Label1) as above is in the Call routine Private Sub Label1_Click() 'change via Call Static lb1Cnt As Integer Dim IsOdd As Boolean lb1Cnt = lb1Cnt + 1 If lb1Cnt / 2 = Int(lb1Cnt / 2) Then IsOdd = False Else IsOdd = True Call TestViaCall(IsOdd) End Sub I think that I should've included more details. The UserForm in question is displayed with labels that are colored. By clicking a label, the color of the clicked label is changed. If the code for the Click event is within the UserForm, everything is OK (color changed and no second initialize event); if in an external module, the above happens (color property changed, but no screen change and a second initialize event). If the UserForm is already in the Project, i.e. not imported, then either method works (color changed and no second initialize event). This simple form is really just some testing code to illustrate the same problem that I'm having with a more complex set of forms. The actual case involves FormA (imported itself from a module) importing FormB (the UserForm here), the user clicking a Label on FormB, then FormA using the result of the Click event in FormB to change a Label property in itself. Getting the result of the FormB Click event can be made/forced to work by using a Call to read the label property from the originating module, but the 'double' initialize event on FormB may force a work-around that I'd rather not have to do if I can help it. Any more ideas? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
UserForm initialize | Excel Programming | |||
userform initialize | Excel Programming | |||
initialize userform, using a sub | Excel Programming | |||
Userform to enter values and shown in same userform in list | Excel Programming | |||
UserForm Initialize event doesn't fire reliably | Excel Programming |