Link to home
Start Free TrialLog in
Avatar of bneuman
bneuman

asked on

How do I add a progress bar?

Using Access97. I want to add to a form and report a simple bar that shows a percentage of time used. Ex: - Employee has 80 hours of vacation a year. They used 20 hours so far. The bar would be a quarter filled with 25% on it. I have this progress bar demo but not sure of how to attach code to make it respond to a calculated field. The demo uses a command button to increment the percentage in the bar. Heres the code for the module:
--------------------------------------
Option Compare Database
Option Explicit

Private Sub Commande1_Click()
   
Me.ctlSbfPBV1.Form.Progress
   
End Sub
--------------------------------------
Private Sub Form_Load()
With Me.ctlSbfPBV1.Form
        .BarColor = vbGreen
        .Orientation = 1
        .Max = 75
    End With
End Sub
--------------------------------------
This demo had about 6 other demos on the form. I took out the code for them.
I hope this is enough information for you.
I will want to use the basic premise to do this with 3 categories on the form once I figure out how to do 1.

Bill
Avatar of ssteeves
ssteeves

The Progress Bar control that I downloaded works like this.  

Place it on the form, and place this code in a button:

ctlProgress.max = 100
ctlProgress.value = 25
ctlProgress.visible = true

Where ctlProgress is the name of the control.

I don't know if this code will work for you, as I don't know what Progress bar you are using.   The default that ships with Access or different version?

ssteeves
If that code does work, you should be able to substitue the .value line to be equal to the calculated field....
Avatar of bneuman

ASKER

ssteeves,
Thanks for the suggestion but this not what I want. Hopefully someone else will respond.

Bill
Avatar of bneuman

ASKER

Let me add.......I'd like to add that I want the progress bar to be filled in by the results from a combobox. I pick on a selection in the combobox and the results fill in the form. I would like this info to fill in a graphical bar. Not sure if its a progress bar or not.

Bill
As SSteves said, I don't know what progress bar you're using. You did give me enough information to get started though.

In the form's On Load event you want to use the same code-

Private Sub Form_Load()
With Me.ctlSbfPBV1.Form
        .BarColor = vbGreen
        .Orientation = 1
        .Max = 75
    End With
End Sub

Of course, you may want to change the bar color or orientation.

In the form's On Current event you want to use this code-

Private Sub Form_Current()
  Me.ctlSbfPBV1.Form.Max = 100 \ (employeeVacationTime \ employeeVacationUsed)
End With
End Sub

I'm assuming the .Max property sets the length of the bar. Without more information on the specific control you are using that's all I can say.
Avatar of bneuman

ASKER

I get a 'divide by zero' error. When I thought I fixed that I got an error in the Max area of the bar. I found out who developed the bar:
sbfProgressBar
'''
''' Marc CHOUTEAU - Octobre 1998
'''
''' JetSofts - Solution Informatique
''' jetsofts@dlnet-inter.fr
''' marc@dlnet-inter.fr

I found out that much of it is in french. Maybe I will start from scratch. Is there a better way?
Avatar of bneuman

ASKER

Adjusted points to 100
Avatar of bneuman

ASKER

I've abandoned my previous attempt at the progress bar. I've up the points to 100 now. Will take any suggestions to make this work. As I stated before I would like a graphical depiction of time used. In this case there will 3 separate bars. One for VactionUsed, PersonalTimeUSed and Tardiness. On a form I have a comboBox to list employees. Click on employee and subform fills in with employee information. Also on form are calculated fields that show Total Vacation, Vacation Used and Vacation Left. Same with personal time. The tardiness is not currently handled this way. I figure if I can get 1 bar to work I can make the other stuff work too. (wishful thinking!) What I want is when I click on employee in comboBox that the progress bars show vacation used and personal used. Like my previous example if a person has 80 hrs per year and he already took 20 hrs, the bar would be a quarter filled with 25% inside. Does this make sense??? I'll up the points another 50 if need be.
Help......

Bill
Do you have the Microsoft ProgressBar Control v5.0? I have made it work with this control, if you have it I'll show you how.
Avatar of bneuman

ASKER

I have Microsoft ProgressBar Control v6.0.
That'll work.

Try this...

Private Sub Form_Current()
If HoursUsed > 0 Then
  PBar.Value = 100 * (HoursUsed / HoursVacation)
Else
  PBar.Value = 0
End If
End Sub
By the way, you'll obviously have to use this on a control named "PBar".
Avatar of bneuman

ASKER

Ok...great finally got it to work. What a feeling when you click on a control and you don't get a compile error!

I have the vacation time working, now on to personal time used. Here is the code I have to use for vacation time used.

------------------------------------
Private Sub indiv_Change()
If [cVacationUsed] > 0 Then
  PBar.Value = 100 * ([cVacationUsed] / [cVacation])
Else
  PBar.Value = 0
End If
End Sub
-------------------------------------

Next question is how do I get the next Bar to work (PBar2)? I assume its where the End If line is.... something like continue to next,loop or something??

Bill
Exactly. You'll start another If...Then...else right after the end if statement.
ASKER CERTIFIED SOLUTION
Avatar of jschrisman
jschrisman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bneuman

ASKER

I'm at home now and just got locked out of my computer at work....Maintenance! I won't be able to do anything until tomorrow morning. I'll get back to you then. Thanks for the subroutine idea. I'll try that in the morning.

Bill
Avatar of bneuman

ASKER

jschrisman,

Everything works just the way I wanted. I really appreciate your help. I've increased the points another 50. Thanks again.
Bill