tags:

views:

88

answers:

2

Hi, From VBA I'm setting a series of text boxes to have DSum controlSources:

Me.Oct.ControlSource = "=DSum('GBPValue', _
                                'MF YTD Actual Income & Adret', _
                                'Month=10 AND Org_Type=[Key]')"
Me.Nov.ControlSource = "=DSum('GBPValue', _
                                'MF YTD Actual Income & Adret', _
                                'Month=11 AND Org_Type=[Key]')"

and then running Me.Recalc to get the values to show up once set. This works fine for the text boxes that are on-screen when the form loads but for ones on the same (very wide) form that are not currently on screen the Recalc seems to do nothing. If I scroll across the form and select the blank fields the values then show up. Is there any way to get the values for every text box on-screen or off to be there on form load or, at worst, when the user scrolled across?

A: 

I don't know what the problem is but you can try this:

...
Me.Oct = DSum('GBPValue', _
                'MF YTD Actual Income & Adret', _
                'Month=10 AND Org_Type=[Key]')
Me.Nov = DSum('GBPValue', _
                'MF YTD Actual Income & Adret', _
                'Month=11 AND Org_Type=[Key]')
...

Set control's text by using DSum directly.

Edit: You can also try refreshing the form after the calculations, i.e. Me.Refresh.

Nick D
this is on a continuous form where Key is a value in the details section of the form so i think i'm stuck with setting the controlsource - if i try to set it directly form vba it sets the column to the same value based on whatever the last 'Key' is (i think ... novice to VBA/Access !)
Ben Roberts
+1  A: 

I can guess why this must be happening: it's likely that Recalc doesn't repaint controls that are not currently visible. So even though the value of the controls has in fact changed, their cached visual appearance still appears empty when the scrolling windows reveals them.

Here's what I'd recommend: create a member function on your form like this:

Function GetMonthValue(Month As Long) As Double
   GetMonthValue = DSum("GBPValue", "MF YTD Actual Income & Adret", _
                 "Month=" & Month & " AND Org_Type=" & [Key])
End Function

The control source for the text boxes can then be set to "=GetMonthValue(1)" and so on. This means that each control's source is declared statically and there's no need to change anything when the form loads. When the current record changes, the value should track, although I haven't verified this with testing.

Paul Keister
I'd guess the same ... have tried this solution and it works like a charm, thank-you so much for this, have been trying to get something to work for a week! (sad but true)
Ben Roberts