<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener("load", function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <iframe src="http://www.blogger.com/navbar.g?targetBlogID=34083602&amp;blogName=LEARN+MS-ACCESS+TIPS+AND+TRICKS&amp;publishMode=PUBLISH_MODE_FTP&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;searchRoot=http%3A%2F%2Fblogsearch.google.com%2F&amp;blogLocale=en_US&amp;homepageUrl=http%3A%2F%2Fwww.msaccesstips.com%2F" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe" allowtransparency="true" title="Blogger Navigation and Search"></iframe> <div></div>
www.msaccesstips.com

LEARN MS-ACCESS TIPS AND TRICKS


International Response Fund

LEARN MS-ACCESS TIPS AND TRICKS

↑ Grab this Headline Animator

Your Ad Here
Friday, January 04, 2008

Progress Bar on Form

Continued from previous article: Progress Meter


We will try the Progress Bar Control on the sample Form that we have already designed earlier, for using with Macros.


NB: This method for Macros found working only on Microsoft Access 2000. When tried in MS-Access 2003 it totally ignores updating the Progress Bar Control, even with the database Formats MS-Access 2000, 2002 and 2003. If any readers found a solution to this problem please share it with me too.


However, you can use this method with our earlier Program replacing the sysCmd() lines for transaction level processing, to view the Progress Bar on your own Form rather than on the Status Bar.


  1. Open the ProgressMeter Form in Design View.

  2. Select ActiveX Control Option from Insert Menu.

  3. Select Microsoft Progress Bar Control, Version 6.0 from the displayed list.

  4. Draw a Progress Bar on the Form as shown in the image below. You have to do some resizing to make it look like the sample below. You can make it any size and shape you prefer.


  5. Progress Bar in Design View


  6. Select the Progress Bar Control (if you have deselected it) and display the Property Sheet (View - > Properties).

  7. Change the following Property Values are shown below:



    • Name = PB2

    • Visible = False



  8. Create a label at the left side of the ProgressBar. Display its Property Sheet and change the following values:


    • Name = lblStatus

    • Visible = False



  9. Select the Command Button on the Form, display the Property Sheet and change the On Click Property.


    • On Click = Spl_Report



    Spl_Report is a Macro in which we have sequenced our processing steps and the Progress Bar will show the current status of its activity.


  10. Save the Form after the changes.



  11. Select Options from Tools Menu. Uncheck the Status Bar under the Show Option group on View Tab. Click Apply and Click OK to close the control.


  12. If you have a Macro running several steps of Queries, Macros and Code, make a copy and rename it as Spl_Report and we will modify it for our demo. A sample Macro Image is given below for reference.


  13. Spl_Report Macro Image


    The first two steps on the Macro’s Action Field have their values set as No.

    The third line Calls the ProgMeter2(1,5,”PB2”) Function with the RunCode macro command with three parameters to initialize the Progress Meter. Values of the parameters represents the following:



    • 1 = indicating that the Progress Bar must be initialized.

    • 5 = This is the maximum number of steps of Queries, other macros or Functions that we are going to run.

    • PB2 = The Name of the Progress Bar Control drawn on the Form.



  14. The Function must be called after every Query running step to update the Progress Bar. But, subsequent calls to the function ProgMeter2(0) needs only with 0 (zero) as Parameter indicating that it is the Progress Meter's updating step.


  15. Insert one row each after every Query on the Macro, Copy and paste the RunCode macro line on the inserted rows calling the Function ProgMeter2(0)
  16. .

  17. At the end of the Macro steps add one more line to call the Function ProgMeter2(2), with the parameter value 2 indicating that the work is over and to turn off the ProgressBar.


  18. If you have added more steps later in the Macro and forgot to modify the initializing value (second parameter 5) the program will ignore further updating calls and wait for the terminating parameter 2 for closing the Progress Bar.


  19. Save the Spl_Report Macro after the above changes.


  20. Copy and Paste the following VB Code into a Global Module in your Project and save it.



  21. Public Function ProgMeter2(ByVal xswitch As Integer, _
    Optional ByVal Maxval As Integer, Optional ByVal strCtrl As String)
    '----------------------------------------------------------
    'Program : Progress Bar Demo2
    'Author : a.p.r. pillai
    'Date : 02/01/2008
    '----------------------------------------------------------
    Static mtrCtrl As Control, i As Integer, xmax As Integer
    Static lbl As Label, frm As Form
    Dim position As Integer, xtime As Date

    On Error GoTo ProgMeter2_Err

    If xswitch = 1 Then 'init control
    Set frm = Screen.ActiveForm
    Set mtrCtrl = frm.Controls(strCtrl)
    Set lbl = frm.Controls("lblstatus")
    mtrCtrl.Visible = True
    lbl.Visible = True
    xmax = Maxval
    i = 0
    DoEvents
    ElseIf xswitch = 0 Then
    i = i + 1
    if i > xmax then
    goto ProgMeter2_Exit
    end if
    position = i * (100 / xmax)
    mtrCtrl.Value = position
    DoEvents
    ElseIf xswitch = 2 Then
    mtrCtrl.Visible = False
    lbl.Visible = False

    Set mtrCtrl = Nothing
    i = 0
    xmax = 0
    Exit Function
    End If

    ProgMeter2_Exit:
    Exit Function

    ProgMeter2_Err:
    MsgBox Err.Description, , "ProgMeter2"
    Resume ProgMeter2_Exit
    End Function


    The Program Logic is the same as of SysCmd() we have used for updating the Status Bar in our earlier example. The only difference is our program updates the Progress Bar on a Form. The built-in Function SysCmd() have other implementations too, with different set of Parameters.


  22. Open the ProgressMeter Form in Normal View. Click on the [Process Orders] Command Button to Run the process steps in Spl_Report Macro.



The Progress Bar will now show up on the Form with the message Working… at the left side Label.


The image of a sample run is given below.



sample run image of Progress Bar


You can implement this method on any Form, like on your Control Screen or on a separate report running parameter Form. When you call the Function ProgMeter2() use the Name that you have given to the Progress Bar Control as third parameter to the Function in place of PB2, that we have used for our example: ProgMeter2(1,5,”PB2”). Subsequent call to the Functions needs only one parameter value 0 for updating the control at each step and 2 to close the Progress Bar at the end.


Further improvement on the design of the Form and the Code is required to prevent Users from closing the Form by accident or straying away from the Form for doing something else making the Form inactive etc. In such situations the program may run into Error.


As I have mentioned at the beginning you can use this function for your VB Routines that updates Table at record level.





Download Demo Database




MS-Access & Mailmerge-2
MS-Access & Mail-Merge
MS-Access Object Documenter
Useful Report Functions
Reminder Pop Up

Labels:

2 Comments:

Anonymous Oliver said…

Hi,

thx for this great Tutorial. It helped me a lot.

For usage in MS Access 2003 try this some code like this:

Private sub workaround_2003
Dim tst As Variant
tst = ProgMeter2(1, 5, "PB2")
tst = ProgMeter2(0)
Sleep (2000)
tst = ProgMeter2(0)
...
tst = ProgMeter2(2)
Sleep (500)
End Sub

It works like charm without using macro's.

Regards Olly

March 26, 2009 1:21 PM  
Blogger a.p.r. pillai said…

Thanks for the Tip Olly.

Regards,
a.p.r. pillai

March 26, 2009 7:08 PM  

Post a Comment

Note:Comments subject to Review by Blog Author before displaying.

Links to this post:

Create a Link

<< Home


Creative Commons License
Learn MS-Access Tips and Tricks by msaccesstips.com is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 India License.



This Page is best viewed with 1280 x 1024 Resolution

   FEATURED LINKS
SITEMAP
Command Button Animation
3D Headings on Forms
MsgBox & Office Assistant
Reminder Ticker
MS-Access & E-Mails
Automated E-Mail Alerts
MsgBox with Options Menu
Colorful Command Buttons
Configure Lotus Notes
Alerts through Network
Running this site has become a costly affair as the revenue from Ads is not sufficient to support it. If you find these pages informative & useful and would like to extend a helping hand, then please do it here.





Link Back to us with this Button

Learn MS-Access

Copy and Paste this HTML Code in your Webpage


Add to Technorati Favorites

Programming Blogs - Blog Catalog Blog Directory
Powered by FeedBurner
Add to Google

Software
Computers blogs
TopOfBlogs




AddMe - Search Engine Optimization Submit Your Site Free!
Go BlogZ Ave Blogs
eBlogzilla Changing LINKS
LS Blogs Blogarama
blog search directory BlogUniverse
Find Blogs in Directory RSS Directory
blogskinny.com ShowcaseBlogs.com
Amfibi

Search Engine Optimization and SEO Tools
Dmegs Web Directory Takeaway for Sale Businesses For Sale
Free Submission Directory Free site submission

Free Listing
 





Free Page Rank Checker

AddThis Social Bookmark Button

Enter your email address:

Delivered by FeedBurner



Top Blogs


Microsoft Access is the Jewell among MS-Office suite of Applications. Its Security features are excellent and works fine in Network environment. MS-Access can link/upload data from any Data Source. Applications that you design should be user-friendly and visually pleasing too. Here I would like to share my experience in Microsoft Access Programming with you and I am sure that you will find them interesting too.

My Photo
Name: Ramachandran Pillai
Location: Cochin, India

I am not an Access Guru and not through MS-Access yet. More to learn and I don’t think that aspect has any end because others have their own style of using this tool. We can learn lot more tricks, other than what we already know, from others too. My programming skills in COBOL, BASIC, Turbo-C, dBase, FoxPro, Visual Basic & Basic HTML attained through self-learning. I wrote my first COBOL Program in 1975 for ICL1901, 3rd Generation Main Frame Computer. Worked as a Computer Operator (NCR VRX8555 Mainframe Machine upto 1990) with M/s. Y.B.A. Kanoo, Saudi Arabia. Started using MS-Access Ver.2 in 1996, when dBase III+ and Foxbase (later version Foxpro) were my favorite DBMS. During Last 13 Year period I have developed more than 45 In-House Applications (medium & small) under MS-Access for our Organization, a leading Automotive Company in Oman. All the Applications are fully Secured and runs under Windows Network. It is my pleasure to share my experience with others. Anything interesting that you would like to share with me, please do. My E-mail Address: aprpillai@msaccesstips.com


If you need a Demo of any of the Topic explained here, send me an E-mail to: aprpillai@msaccesstips.com
with the Topic Description, I shall try to send a sample database to you.


Access Tips | Email | Reports | Report Tricks | Graphs | Forms | Menus | Animation | Security | Internet | How TOs | Linking | Query | Progress Meter | Alerts | Process Tips | Access Functions |




Site Designed by:www.msaccesstips.com