Progress bar on form based on field data? (1 Viewer)

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:24
Joined
Aug 30, 2003
Messages
36,118
I guess I should have said instead of the button to be more clear.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:24
Joined
Feb 28, 2001
Messages
26,999
Paul has the best solution, but since you claim to be new to VBA, here is a LITTLE bit more detail.

First, put 30 Yes/No flags in the common declaration area of your form's class module. Write a little subroutine that resets all flags to False. Call this routine from the form's Current routine (if a bound form) or from the form's Load routine.

Now build a subroutine you can call that counts True flags among that set of 30. When you call that routine, update your progress bar. I know you have seen many ways to do this. My own favorite involves creating two overlaid rectangles, one with non-blank BackColor, the other with non-blank BorderColor. Then I would place the rectangle with BackColor and set its width according to a formula based on (the number of filled text boxes * the width of the other rectangle / 30 ). You might wish to have a special case where you set the width to 1 if no text boxes are filled. That 1 is 1 TWIP, not 1/30 of the width of the other text box. In other words, don't set width to 0.

Next, have LostFocus routines or AfterUpdate routines (your choice) on every control that is in this list. In either case, you would have to use the code to set a flag that says that the box does or does not have something useful in it. (If someone erases a box, you have to maybe DECREMENT a counter, not INCREMENT it.) At the end of the routine, after the flags are set or cleared as appropriate, call the routine that updates the progress bar.

Finally, when you do whatever you do to save your data, presuming you erase the 30 boxes before allowing the next action, remember that events don't always fire when VBA does something that normally would be done by the users. For example, LostFocus does not fire when VBA changes a box's contents because VBA doesn't need to have focus to make that kind of change.

This is a slightly more detailed look at ONE WAY to do this. BY FAR not the only way.
 

Users who are viewing this thread

Top Bottom