Binding the ProgCtrl ActiveX Control to a value on my form

Posted on 2007-07-23
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
    LVL 84
    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:\ProgSamples\

    LVL 75

    Assisted Solution

    by:DatabaseMX (Joe Anderson - Access MVP)
    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 84
    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>.
    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    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

    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 84

    Accepted Solution

    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

    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

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    "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

    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 84
    <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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
    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…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now