Binding the ProgCtrl ActiveX Control to a value on my form

Posted on 2007-07-23
Medium Priority
Last Modified: 2008-01-09
I'm a little new to ActiveX contorls.
One of the values on my form is called "PercentComplete".  It's a numberic value that contains the percent completed of projects in my database.

I've added the Microsoft Progress Contol Bar (ProgCtrl) to my form.  How do I tell the ActiveX Controll to run using the value Me.PercentComplete?

So, if the value is 27% compelte, the bar would visually indicate this.

I'm guessing this would be done in the OnUpdated event of the control, but I'm a little unsure of the syntax.

Thanks in advance,

Question by:dsg138
  • 4
  • 3
  • 3
LVL 85
ID: 19548343
You could use the form's Current event, or Load/Open event, depending on exactly what you're doing with the progress bar. If this is a project wide setting, then probably the Load/Open event. I'm not overly familiar with the control you mention, but I'd suspect that you would need to set the .Value of the Progress bar in some fashion.

Also: You'd be well advised to NOT use this control ... it's buggy, and very prone to versioning issues. Many devs build their own progress bar with boxes and such. I've got a sample on my website that shows how to do this:


LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 200 total points
ID: 19548851
Here is some info from an Advisor article.  I'm posting this because unless you are a subscriber, you cannot access the article.  Sorry for the long post ... hope it helps.  mx


Using the ProgressBax ActiveX control

You have one other choice: the ProgressBar ActiveX control that's part of the "Common Controls" that come with Windows (found in either MSComCtl.ocx or ComCtl32.ocx). The ProgressBar control offers you the benefits of my custom-built solution (flexibility in size and position) along with one additional property I'll point out.

To add the ProgressBar ActiveX control to your form, open your form in Design view and select Insert > ActiveX Control from the menu. Scroll through the list of available controls until you find the one for Microsoft ProgressBar Control (figure 3). After you've found it, select it and click on the OK button. A rather ugly rectangle appears on your form that you can move to wherever you want the control to display, and resize it to taste.

If you right-click on the control, you'll get a context-sensitive menu choice that will let you look at the properties of the control. (See figure 4 for how to select the properties, and figure 5 for the Properties window.)
You use this control in the same way you used the previous approaches. The control has a Max property you set to indicate the maximum value you expect to see, and a Value property you set to indicate the current value. The progress bar also has a Min property you can use if you don't want to go from 0 to Max.

Here's the relevant code to use this control in the sample database:

Private Sub tglProgress_Click()

  If Me.tglProgress Then
    Me.objProgress.Max = _
      Me.txtDuration / Me.cboRefreshRate
    Me.TimerInterval = Me.cboRefreshRate * 1000
    Me.TimerInterval = 0
  End If

End Sub


Private Sub Form_Timer()

Static lngCounter As Long

Dim lngMaxValue As Long

  lngMaxValue = _
    (Me.txtDuration / Me.cboRefreshRate)

  If lngCounter >= lngMaxValue Then
    lngCounter = 0
    Me.TimerInterval = 0
    Me.tglProgress = Not Me.tglProgress
    lngCounter = lngCounter + 1
    Me.objProgress.Value = lngCounter
  End If

End Sub

LVL 85
ID: 19549379
mx: Be careful about posting articles from the Access Advisor. I did this in a newsgroup once and got a nice (and well-deserved) tongue lashing from the author regarding copyrights and such <g>.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 75
ID: 19549429
good point.  
It was just part of the article ... and I've been a paid subscriber since inception ...  so, if they hassle me, I will do it right back, lol.


Author Comment

ID: 19555835
Thank you both for the suggestions.

LMS, I've downloaded your sample and it's really cool, but way more than I need to do.
MX, I think your solution is also more than I need.  I really don't need timer intervals at all.

Basically, right now, when my users open up my form (a single form), they can see a text box that says PercentComplete.  They will see something that says 85% in the text box.  All I want to do is give them a visual indicator of that 85% for this record.  This should not invove any timers or durations.

I'm thinking it should be as simple as something like this:

ProgBar.Value = me.PercentComplete

But that was just pseudo code and I'm not sure of the syntax.

Thank you both for your help so far.  
LVL 85

Accepted Solution

Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points
ID: 19556035
All progressbars work on the concept of Max/Min Vaues (i.e. Duration) and CurrentValue ... Timers would be needed if this is a "live" process, but for ANY progress bar, you must set the Max Value (i.e. the value when complete), the Min Value (i.e. where things Start), and the CurrentValue (i.e. where you are in the Process).

If you're referring to this control (check the Properties dialog for confirm this):

OLE Class: ProgCtrl
Class: MSComctlLib.ProgCtrl.2

Then you'd have to set the Min, Max, and Value of the control at some point. Typically, you'd set Min and Max when the form Opens/Loads, then set the Value in the Form's Current event:

Sub Form_Open()
End Sub

Sub Form_Current()
  Me.ProgressBar2.Value = Me.PercentComplete
End Sub

Note that you might also use the Open/Load event to set the .Value ... this would depend on how your database is setup, and exactly what information you're trying to dispaly.

Again, I caution you against using this control if the database will be distributed to other users, since you're almost certain to run into versioning issues, and you'd need to do a LOT more work to correctly distribute this ... but if this is for one user, or for a few users in the same office, then you can likely deal with those issues quickly.

Additional: When using ActiveX controls, it's difficult to see the Properties, Methods, and Events available in Access unless you declare an variable of the correct type, then set that variable to the actual control's Object property. So, in the case of this progressbar, you'd do this:

Dim pgb As ProgressBar
Set pgb = Me.ProgressBar2.Object

Assuming your ProgressBar is name "ProgressBar2" ... after doing this, IntelliSense then provides you with the standard dropdown list of Methods/Properties available for that object ... so you could do this, assuming you have a Textbox name "txtValue":

With pgb
  .Min = 0
  .Max = 100
  .Value = Me.txtValue
End With


Author Comment

ID: 19556197
thanks... Other users will definately be using this.  

So if I used the one from your sample...
what part of the code would I modify to add something like:  
Me.ProgressBar2.Value = Me.PercentComplete.
Is that the vdata value that I'd be modifying?

Didn't realize that was so complex so I'm increasing the points.  Thanks!
LVL 75
ID: 19557221
"MX, I think your solution is also more than I need.  I really don't need timer intervals at all."

Actually, that was just a little background on how to use the control you are using :-)


Author Comment

ID: 19569828
MX, thanks for the background.

LSM, I got this to work with the VB code you've provided.  I think this should be fine since all of the users have the same version of Access.  But I will be cautious for versioning issues like you've mentioned.  We'll see how this will do for now.  Thanks again.
LVL 85
ID: 19570056
<I think this should be fine since all of the users have the same version of Access.>

By "versioning conflicts" I'm referring to conflicts with the ProgressBar, not Access. If your users have an older version of the ProgressBar control on their machines, you'll end up with errors and a non-responsive program at best (crashed system at worst) ... I don't know what your target environment will be, but in general if your users would be running older versions of operating systems (or lower service packs) you could potentially run into some issues. As I mentioned before: you would be much, much better off using a non-ActiveX control for this ... either way, best of luck and glad you got it working.

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question