Results 1 to 8 of 8
  1. #1
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389

    Simple Progress Bar for your forms

    NOTE: With technique shown by Isladogs in post#2 below, I've been able to revise my progress bar to eliminate the flicker. See Post#3 below for new download.




    SimpleProgressBar-davegri-v01.zip

    Click image for larger version. 

Name:	pbar.png 
Views:	245 
Size:	23.5 KB 
ID:	46906

    Have you ever searched for a progress bar for your forms only to run into blind alleys with custom class modules, convoluted forms with complex code behind them? I did too, and thought there must be a better way. So a bit of tinkering with an idea presented by a user named Hamzaable at a site I can't remember produced this result.

    A progress bar needs to know two things: The max value it represents (the full bar), and the current percentage of the full bar to display.
    The max value, once determined does not change. The current percentage changes dynamically and the bar tracks its progress by expanding from left to right.

    If you cannot determine either of these values, no progress bar can reliably work. If you can, then here's a simple to implement solution. Be sure to read the notes in the code.

    The bar is built with just 2 controls, an image and a rectangle. The image is within the rectangle, with the rectangle being the boundary of the bar.
    To deploy the progress bar on your form, copy the image and rectangle to an appropriate spot. Copy all the code behind the form to your form. You will need to change some of that code in order to supply your max value and the current percentage. To change the width of the bar, change the width property of the rectangle, not the image. You may or may not need to copy the code module 'modProgress', see below.

    There are 2 forms in the demo. One form contains all code necessary for full implementation. The second form requires 'modProgress'. The second form setup might be more appropriate if you have more than one form that needs a progress bar, as each form would not need to duplicate all the code behind itself.
    Last edited by davegri; 12-21-2021 at 03:55 PM. Reason: Note for update

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Hi Dave
    I tried both examples. Whilst it does the job, I found there was a lot of flickering each time the bar is updated which I found distracting.

    You might be interested in my approach which also uses simple code with 3 procedures in a standard module SetupProgressBar, UpdateProgressBar & HideProgressBar.
    There is no flickering.

    Progress Bar - Mendip Data Systems (isladogs.co.uk)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    SimpleProgressBar-davegri-v02.zip

    With technique shown by Isladogs in post#2 above, I've been able to revise my progress bar to eliminate the flicker. The major revision was to change the moving bar from an image to a superimposing rectangle. The basic code is unchanged from V01 in original post.

    A progress bar needs to know two things: The max value it represents (the full bar), and the current percentage of the full bar to display.
    The max value, once determined does not change. The current percentage changes dynamically and the bar tracks its progress by expanding from left to right.


    If you cannot determine either of these values, no progress bar can reliably work. If you can, then here's a simple to implement solution. Be sure to read the notes in the code.


    The bar is built with just 2 rectangle controls, BoxBottom and BoxTop, superimposed. BoxTop is within BoxBottom, with BoxBottom being the boundary of the bar.
    To deploy the progress bar on your form, copy the 2 rectangles to an appropriate spot, maintaining their left alignment. Copy all the code behind the form to your form. You will need to change some of that code in order to supply your max value and the current percentage. To change the width of the bar, change the width property of BoxBottom. You may or may not need to copy the code module 'modProgress', see below.


    There are 2 forms in the demo. One form contains all code necessary for full implementation. The second form requires 'modProgress'. The second form setup might be more appropriate if you have more than one form that needs a progress bar, as each form would not need to duplicate all the code behind itself.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    MUCH better !!!!!

    P.S. length mis-spelled as lenght on both forms!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    P.S. length mis-spelled as lenght on both forms!
    Thanks, should have used 'width' anyway!

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Have you ever searched for a progress bar for your forms only to run into blind alleys with custom class modules, convoluted forms with complex code behind them?
    I've been thinking of the above quote for a week now. I've been using the same progress bar for 15 years + (similiar to yours) and I have a pretty bad obsession with custom classes. It's always hard to come up with ideas for them and this seemed like a good one.

    After opening a recordset, you instantiate the class and initialize it
    The arguments passed to the class are the record count and a Modulus value. Use a lower Modulus value for small record counts and a higher one for larger record counts.
    This helps regulate the speed of the progress bar. Future update to set the Modulus value dynamically.

    Code:
        Set cPB = New clsPBar1  
    
    
        cPB.InitProgBar rs.RecordCount, 5

    In the loop there is a call to the class passing the recordset AbsolutePosition as an argument. To avoid 0 division errors add 1 to AbsolutePosition as it is zero based.

    Code:
        Do Until rs.EOF
    
    
            'Your code here
    
    
            cPB.UpdateBar (rs.AbsolutePosition + 1)  
    
    
            rs.MoveNext
        Loop
    Works in a for loop too.
    Code:
        Dim i As Long
    
    
        Set cPB = New clsPBar1  
    
    
        cPB.InitProgBar 300, 2  
    
    
        For i = 1 To 300  
    
    
            cPB.UpdateBar i
    
    
        Next i
    4 lines of code to implement (including the variable declaration)
    Still have some tweaking, testing, and additions in mind but its a start.
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    [QUOTE=moke123;488026]I've been thinking of the above quote for a week now. I've been using the same progress bar for 15 years + (similiar to yours) and I have a pretty bad obsession with custom classes. It's always hard to come up with ideas for them and this seemed like a good one.

    Moke, it wasn't directed at anyone in particular. I think a lot of developers steer away from tools that they don't readily understand, worrying about running into problems down the road with no easy way to troubleshoot and fix it.
    Class modules are a tool to get a desired result. The same result can be achieved using other more familiar tools. And that's why I avoid developing or using them - I don't want to burden my users (or adopters) with code they might find difficult to maintain.
    We all have quirks, habits and favorite techniques. And we can all display them here.

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Moke, it wasn't directed at anyone in particular.
    I didn't think it was. It's just that it was stuck in the back of my head all week that I wanted to give it a go. It's not the first time you have inspired me.
    You can see by the timestamp that I spent way too much time on it.

    I think a lot of developers steer away from tools that they don't readily understand
    I agree and I'm one of them. I just like the challenge of trying to learn them.

    I'm on vacation all week and I've got a lot of time to kill, so feel free to keep the ideas coming

    Edit: Well that didn't take you long. The Application Parts tip in this thread https://www.accessforums.net/showthread.php?t=85039 is amazing. I am inspired once again.
    Last edited by moke123; 12-28-2021 at 01:05 PM.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Progress Bar
    By pkstormy in forum Code Repository
    Replies: 3
    Last Post: 09-21-2012, 10:27 AM
  2. Replies: 1
    Last Post: 06-01-2012, 02:40 PM
  3. Simple Requery Structure - Continous Forms
    By JeffG3209 in forum Programming
    Replies: 8
    Last Post: 06-10-2011, 07:18 PM
  4. Simple forms/queries question (I hope!)
    By Remster in forum Access
    Replies: 6
    Last Post: 09-07-2010, 12:08 PM
  5. How to use progress bar
    By marianne in forum Access
    Replies: 19
    Last Post: 04-01-2009, 09:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums