Step or run - different result

  • Thread starter Thread starter Rolf Rosenquist
  • Start date Start date
R

Rolf Rosenquist

I have a form to calculate daily takings. A button starts the code to open 3
other forms (with Echo False), that each calculates 3 different variables
that should be reported in the first form.

The result is zero from all of them by running. But when I step through the
code, everything is OK. I guess, that those 3 other forms take so long time,
that they don't have their values ready, when the first form asks them for
their values.

Is there a possibility to make a delay of for instance 1 or 2 seconds,
before the command to get the values? I tried with Me.TimerInterval = 2000,
but that did not work. Or is there a better way to get the values for the
user?
/ Rolf
 
No need to think more about it.
I did the opening of those 3 forms when the first one got opened. Then they
had time to get their results, before the user hits the calc-button. -
Perhaps not so beautiful, but at least it works.
/ Rolf
 
DoCmd.OpenForm "dagrapp1a", acNormal 'this takes too long time
[Belopp1] = [Forms]![dagrapp1a]![TotPris] 'before this can be
read
[Belopp3] = [Forms]![dagrapp1a]![TotMoms]
[Belopp1] = [Belopp1] - [Belopp3]
DoCmd.Close acForm, "dagrapp1a"

/ Rolf
 
Rolf,

Refering to controls with calculated ControlSources (=Sum([Field]) is a
risky business. The problem is they are not static. Access strobes the
latest results continuosly to such controls, and while it displays them
reliably to the form, reading the control from code will return the
proper result only a small fraction of the time.

The only reliable way is to find the sums is to use a form-level
function, like:

Private Function fsgTotalHours() As Single

Dim sgOut As Single
Dim rRS As dao.Recordset

fsgTotalHours = 0
sgOut = 0
Set rRS = Me.RecordsetClone

With rRS
If .RecordCount > 0 Then .MoveFirst
Do While Not .EOF
sgOut = sgOut + CSng(Nz(!TaskHours))
..MoveNext
Loop
End With

fsgTotalHours = sgOut

End Function
 
Back
Top