Counting in a form - progress/status

stevendt

Registered User.
Local time
Today, 14:23
Joined
Nov 17, 2016
Messages
13
Hi,
I have form that has some text boxes at the bottom that are populated by the Count() function. They work fine, but the counts can take quite a few seconds to complete when the form is loaded/changed.

It is it possible to display the hourglass cursor (or some other text) while the counts are being done? The time taken can vary, depending on the filter being set, so I don't want a fixed time, but would like to give the user some indication that something is happening.

Any help would be greatly appreciated

regards
Dave
 
Check out the DoCmd.Hourglass() method, and the Screen.Mousepointer property.
 
Check out the DoCmd.Hourglass() method, and the Screen.Mousepointer property.

In which event would change it to an hourglass and in which you change it back?
 
In which event would change it to an hourglass and in which you change it back?

Yes, I did think of DoCmd.HourGlass(), but could not think of a suitable On event either.

I tried checking for the values in the counters being Null or 0, but without success :-(

regards
Dave
 
I would use the current event of the form, like...
Code:
Private Sub Form_Current()
on error goto handler
   docmd.hourglass true
   me.tbPeople = DCount("*", "tPeople", "ParentID = " & me.PersonID)
   me.tbHours = DSum("Hours", "tHours", "WorkerID = " & me.PersonID)
final:
   docmd.hourglass false
   exit sub
handler:
   msgbox err & " " & err.desription
   resume final
end sub
...and the error handling is important to make sure the hourglass gets turned off, even if an error occurs.
 
Hi Mark,

thanks for that, I think I'm getting there. . .

At the moment, the counts are configured as a formula in the Control Sources of the textboxes. Your VBA is obviously doing the counting in the Current Event action.

Obviously, I don't need both methods counting, but are there any advantages/disadvantages to doing it one place, rather than the other?
(Apart from having access to VBA functions when doing it in code)

regards
Dave
 
VBA has the advantage that you can insert other functions around your operation--like showing an hourlgass before, and hiding it after. VBA is also, to me, more explicit. With a glance at your code you can get a good idea of what happens with your form. VBA also provides much simpler and clearer IF...ELSE...END IF branching. In a ControlSource you have to use IIF(), which when nested becomes practically unreadable, so VBA, to me, is easier to maintain.

ControlsSources are nice if you don't know how to write code, but finding out what they do is a headache, because you have to drill down on each one, expand the text of the ControlSource property, and then back out to view the next one, and there is no 'dashboard' or overall view of how they may work together.

Those are my thoughts on how they compare. I almost only use the ControlSource to bind a control to a field in the RecordSource of the form. Unbound controls I almost always set in code.
 
Thanks Mark,
that is useful info - much appreciated
regards
Dave
 

Users who are viewing this thread

Back
Top Bottom