• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Fire Tab_Change() upon page clicked after subform is updated

I need to fire the below code when the page is clicked but after several fields which are needed for calculation update with new data pulling from 2 subforms.

 Me.curTotalLayerPremium = Me.calccuml1LayerTotal
    Me.curTotalReinsPremium = 0
    Me.curTotalUmbChargedPremium = Nz(Me.curTotalLayerPremium, 0) + Nz(Me.curTotalReinsPremium, 0)

The problem I'm running into placing this on the tab_chage is that the event fires before me.calccuml1layertotal has a chance to pull the updated values from the 2 subforms.

(Am I making any sense with this?)

As always any help is greatly appreciated.

Rose Marie

0
fyrerose
Asked:
fyrerose
  • 14
  • 13
  • 2
1 Solution
 
Eric ShermanAccountant/DeveloperCommented:
Which version of Access are you using????

ET
0
 
fyreroseAuthor Commented:
Access 2002  (soon to be 2003 , hopefully)
0
 
puppydogbuddyCommented:
Try inserting this code as the first line of the tab control change event:

'commits any changes
If Me.Dirty Then Me.Dirty = False
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Eric ShermanAccountant/DeveloperCommented:
>>>>The problem I'm running into placing this on the tab_chage is that the event fires before me.calccuml1layertotal has a chance to pull the updated values from the 2 subforms.<<<<<<

Try this ...

1.) Update me.calccuml1layertotal based on the OnCurrent Event for your form.

OR

2.) Update me.calccuml1layertotal based on the AfterUpdate Event for your sub-forms.


ET
0
 
fyreroseAuthor Commented:
puppydogbuddy,

this is what I have coded so far.

****************

Private Sub tab1_Change()

If Me.Dirty Then Me.Dirty = False

If Me.tab1.Value = 2 Then

Select Case Me.intPolicyLimit

    Case 1
   
    Me.curTotalLayerPremium = Me.calccuml1LayerTotal
    Me.curTotalReinsPremium = 0
    Me.curTotalUmbChargedPremium = Nz(Me.curTotalLayerPremium, 0) + Nz(Me.curTotalReinsPremium, 0)

End Select

End If


End Sub

******************

When I click on page 2 nothing happens, however if I click on any other page and then back on page 2 it fires......
0
 
puppydogbuddyCommented:
the code I gave you should be in the tab control on the main form, not  on the individual tabs. .the dirty = false statement should commit any unsaved changes from the subforms.

Private Sub TabCtl0_Change()       '<<<<<<<should be for tab control on the main form

If Me.Dirty Then Me.Dirty = False

    Me.curTotalLayerPremium = Me.calccuml1LayerTotal
    Me.curTotalReinsPremium = 0
    Me.curTotalUmbChargedPremium = Nz(Me.curTotalLayerPremium, 0) + Nz(Me.curTotalReinsPremium, 0)



End Sub
0
 
fyreroseAuthor Commented:
puppydogbuddy,

That is the tab control, I guess I should've named it something else.  I can see now how misleading the name of it is.
0
 
puppydogbuddyCommented:
It didn't work????

 try doing a requery just before the end sub

Private Sub TabCtl0_Change()       '<<<<<<<should be for tab control on the main form

If Me.Dirty Then Me.Dirty = False

    Me.curTotalLayerPremium = Me.calccuml1LayerTotal
    Me.curTotalReinsPremium = 0
    Me.curTotalUmbChargedPremium = Nz(Me.curTotalLayerPremium, 0) + Nz(Me.curTotalReinsPremium, 0)

Me.Requery                               '<<<<<<<<<<<<<<<<<<

End Sub
0
 
fyreroseAuthor Commented:
That works but it makes the screen flicker when I click on Page 2........  Is there anything I can do about the flicker?
0
 
puppydogbuddyCommented:
I have never had that problem, but try this  after the requery statement, adapting the code to your actual page numbers/page indexes for the tabcontrol:(I am hoping that the setfocus statement will alleviate the flicker).

Me.Requery
_____________________________Additional code
Select Case Me.TabCtl0.Value
    Case Is = 0   'note Me.Page1.PageIndex = 0
        TabCtl0.Pages.Item(0).SetFocus
    Case Is = 1   'note  Me.Page2.PageIndex = 1
        TabCtl0.Pages.Item(1).SetFocus
    Case Is = 2   'note  Me.Page3.PageIndex = 2
        TabCtl0.Pages.Item(2).SetFocus
End Select

End Sub
0
 
puppydogbuddyCommented:
could this be the answer to your flickering???  if it is, then you can probably disregard the previous post.

           http://www.allenbrowne.com/ser-46.html
0
 
fyreroseAuthor Commented:
I tried using the module and it still flickers.  I've noticed the screen does this whenever I use me.requery.

I added your code also and it still flickers.
0
 
fyreroseAuthor Commented:
If I remove me.requery the flickering stops....
0
 
puppydogbuddyCommented:
ok. maybe we need to requery just the subform control.

instead of me.requery try this using the actual :
me.yoursubformcontrol.requery
me.yoursubformcontrol.requery
0
 
puppydogbuddyCommented:
oops ! should have been only 1 line for requery of subformcontrol. disregard second line.
0
 
fyreroseAuthor Commented:
the main form needs to be requeired not the subform

this is what I need recalculated when the subform changes

Me.curTotalLayerPremium = Me.calccuml1LayerTotal
    Me.curTotalReinsPremium = 0
    Me.curTotalUmbChargedPremium = Nz(Me.curTotalLayerPremium, 0) + Nz(Me.curTotalReinsPremium, 0)
0
 
puppydogbuddyCommented:
ok, try the following instead of me.requery:

me.recalc    


if me.recalc doesn't work, try this:

me.refresh
0
 
fyreroseAuthor Commented:
nope, neither worked
0
 
puppydogbuddyCommented:
try moving this line:
       If Me.Dirty Then Me.Dirty = False

to the line before Me.Requery, and comment out me.requery, then try it.

if doing that does not update the computation, uncomment me.requery and then try it.
0
 
fyreroseAuthor Commented:
That doesn't help either.  I noticed the form also flickers when moving from one record to the next.  
0
 
puppydogbuddyCommented:
OK, lets try another approach....turn screen painting off and on.  

Me.Requery
_____________________________Additional code

Me.Painting = False      'turn off screen painting until subform has focus
Select Case Me.TabCtl0.Value
    Case Is = 0   'note Me.Page1.PageIndex = 0
        TabCtl0.Pages.Item(0).SetFocus
    Case Is = 1   'note  Me.Page2.PageIndex = 1
        TabCtl0.Pages.Item(1).SetFocus
    Case Is = 2   'note  Me.Page3.PageIndex = 2
        TabCtl0.Pages.Item(2).SetFocus
End Select
Me.Painting = True
0
 
fyreroseAuthor Commented:
nope still flickering..... grrrr
0
 
puppydogbuddyCommented:
LOL.....ooh sooooo frustrating!!!....
on the basis of what Access help says about repainting, I think we need to apply it to each of the subforms, so let's comment out the setfocus on the tab control and try to setfocus on the subform:

Me.Painting = False      'turn off screen painting until subform has focus
Select Case Me.TabCtl0.Value
    Case Is = 0   'note Me.Page1.PageIndex = 0
    '    TabCtl0.Pages.Item(0).SetFocus
         Me.YourSubform1.SetFocus    
Case Is = 1   'note  Me.Page2.PageIndex = 1
    '    TabCtl0.Pages.Item(1).SetFocus
         Me.YourSubform2.SetFocus
    End Select
Me.Painting = True


_______________________________From Access Help____________________________
Setting the Painting property for a form or report to False also prevents all controls (except subform or subreport controls) on a form or report from being repainted. To prevent a subform or subreport control from being repainted, you must set the Painting property for the subform or subreport to False. (Note that you set the Painting property for the subform or subreport, not the subform or subreport control.)

The Painting property is automatically set to True whenever the form or report gets or loses the focus. You can set this property to False while you are working on a form or report if you don't want to see changes to the form or report or to its controls. For example, if a form has a set of controls that are automatically resized when the form is resized and you don't want the user to see each individual control move, you can turn Painting off, and then move all of the controls, then turn Painting back on.

 
0
 
fyreroseAuthor Commented:
puppydogbuddy,

It's not the subforms per se that are flickering, it's the tab control.  Everything above the tab control does not flicker.  Everything on the tab control, whether it's a subform or regular text controls, flicker.
0
 
puppydogbuddyCommented:
that is why I want to turn painting off until subform has focus...hopefully flickering before focus occurs will be gone.
0
 
fyreroseAuthor Commented:
I don't quite understand why you're trying to keep the subform on page 0 from flickering when the code is firing when I click on page 2 which has no subforms?a
0
 
puppydogbuddyCommented:
keep in mind that I don't know what you have on each page or how you have indexed them...that is why I've been telling that you have to adjust my code to your specifics.  In your case, if clicking on page 2 is flickering than modify the code I gave you so that it incorporates the pages that are flickering.
0
 
fyreroseAuthor Commented:
puppydogbuddy,

Your approach gave me an idea.  This is what I'm using now.

Private Sub tab1_Change()

If Me.Dirty Then Me.Dirty = False

    If Me.tab1.Value = 2 Then
   
    Me.Painting = False

        intPolicyLimit_AfterUpdate

    Me.Requery

    Me.Painting = True

    End If

End Sub

NO FLICKER!!

yay!

Thanks so much for your help.

Rose Marie
0
 
puppydogbuddyCommented:
Wow!! way to go! Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 14
  • 13
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now