• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3208
  • Last Modified:

Binding the ProgCtrl ActiveX Control to a value on my form

Experts,
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,

-Dan
0
dsg138
Asked:
dsg138
  • 4
  • 3
  • 3
2 Solutions
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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:

www.infotrakker.com\ProgSamples\ProgBar.zip

0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
  Else
    Me.TimerInterval = 0
  End If

End Sub

and

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
  Else
    lngCounter = lngCounter + 1
    Me.objProgress.Value = lngCounter
  End If

End Sub

0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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>.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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.

mx
0
 
dsg138Author Commented:
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.  
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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()
  Me.ProgressBar2.Min=0
  Me.ProgressBar2.Max=100
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


0
 
dsg138Author Commented:
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!
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"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 :-)

mx
0
 
dsg138Author Commented:
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.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
<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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now