Solved

Progress Bar from Windows API

Posted on 2001-06-02
21
465 Views
Last Modified: 2007-11-27
Does anyone have sample code to call up the progress bar
from the windows API or have a link to the code?.
A sample mdb would be best.
Also, is there any way to count the records in a text file
before import?
0
Comment
Question by:nschulz777
  • 14
  • 5
  • 2
21 Comments
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6150145
Hi nschultz,

Status Bar:

The following are routines written in a form called Status Bar:

------------------
Option Compare Database
Option Explicit

Dim Stat As ProgressBar           ' An pointer to MyStatusBar
Dim CurrentProgressValue As Long  ' Holds Current value for the progress
Dim InProgress As Boolean         ' Is set to true before the process begins

Private Sub Form_Current()
    ' Notice that after the termination of your process, the pass through this Sub.
    ' Therefore, it is neccessary to stop monitoring, if it was not done yet...
    If InProgress And CurrentProgressValue >= Stat.Max Then
        InProgress = False
        Stat.Value = GetMaxValue
        DoCmd.RepaintObject
        Me.TimerInterval = 0
    End If
End Sub

Private Sub Form_Open(Cancel As Integer)
    InProgress = False
    Set Stat = Me!MyStatusBar.Object
End Sub

Private Sub Form_Timer()
    ' In your application, you should get some REAL value that represents the
    ' actual progress of your routine.
    ' If you make a query, which you want to monitor, then it is reccomended that
    ' you set the query result to a Query or a Table. This way, you can set a routine
    ' that will look at the result and return a value (such as the number of records
    ' already created).
    ' the command should look something like the following:
    '
    ' CurrentProgressValue = GetCurrentQueryCurrRecords
    '
    ' The following command is made to emulate the progress in this example
    '
'    Debug.Print "CurrentProgressValue=" & CurrentProgressValue
'    Debug.Print "Stat.Min=    " & Stat.Min
'    Debug.Print "Stat.Max=    " & Stat.Max
    If CurrentProgressValue < Stat.Max Then
        ' Get some progress...
        Stat.Value = CurrentProgressValue
    Else
        ' The routine have reached it's Max Value
        ' Therefore, set the bar to it's Max Value
'        Stat.Value = Stat.Max
        ' and stop monitoring the progress
'        InProgress = False
'        Me.TimerInterval = 0
    End If
    DoCmd.RepaintObject
End Sub


Private Sub StartTheProcess_Click()

    ' Initialize InProgress, Bar-Min, Bar-Max and CurrentProgress values...
    InProgress = True
    CurrentProgressValue = GetMinValue       'See the routine below
    Stat.Min = GetMinValue           'See the routine below
    Stat.Max = GetMaxValue           'See the routine below
   
    'and make sure to monitor the process every half of a second...
'    Me.TimerInterval = 500
    Me.Refresh
    ' Now it's o.k. to start the procedure
    DoMyRoutine                              'See the routine below
   
End Sub

' The following GetCurrentQueryCurrRecords function is a sample function to return
' the current RecordCount (total records) in a Query or a table
Private Function GetCurrentQueryCurrRecords() As Long
    Dim DBs As Database
    Dim Rst As Recordset
    Dim strSQL As String
   
    ' Replace qMyQuery to the actual name of your query or table name
    strSQL = "SELECT * FROM qMyQuery"
    Set DBs = CurrentDb
    Set Rst = DBs.OpenRecordset(strSQL)
    Rst.MoveLast
   
    GetCurrentQueryMaxRecord = Rst.RecordCount
   
    Rst.Close
    Set DBs = Nothing

End Function

Private Function GetMinValue() As Long
    ' This function returns the Min-Value of the status bar.
    ' You may use it to set any value which is suitable to your needs...
    GetMinValue = 1
End Function

Private Function GetMaxValue() As Long
    ' This function returns the Max-Value of the status bar.
    ' You may use it to set any value which is suitable to your needs...
    GetMaxValue = 1000
End Function

' Use the following SUB to execute your query...
Private Sub DoMyRoutine()
    Dim i As Long, j As Long
   
    j = 1
'    Debug.Print "Me.TimerInterval=" & Me.TimerInterval
    For i = Stat.Min To Stat.Max
        If j > 20 Then
            j = 1
        End If
'        Debug.Print "j = " & j
        j = j + 1
        CurrentProgressValue = i
        Form_Timer
    Next i
    Me.Refresh
End Sub
------------------------------------

On the form, place a ActiveX control with the following parameters:
OLE Class: ProgCtrl
Class: MSComctlLib.ProgCtrl.2


Hope this helps,

Nosterdamus
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6150147
Notice that the Sub StartTheProcess_Click() procedure is linked to a button called StartTheProcess which I created in the form for test purposes only. In your app, you can delete this sub.

Nosterdamus
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6150150
I suggest that you look at the MS Access Help for the TransferText action, it is possible that it would let you accomplish what you need much faster than manipulating the text file your-self via code.

Nosterdamus

P.S. Hope this is the last comment I have for the moment... ;-)
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 2

Author Comment

by:nschulz777
ID: 6150385
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6150424
Thanks Nosterdamus, is there no way to do this without an active-x control (direct from wondows API)
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6150428
Of course when I spell something wrong it posts - eg "windows" not wondows.
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6150446
Hi nscultz,

None that I know of (still, it doesn't say that there isn't one)...;)

Nosterdamus
0
 
LVL 4

Expert Comment

by:nmilmine
ID: 6151356
Hi nscultz

I can send you an example using the Microsoft Progressbar Control that comes with Access 2000

Let me know your email address and will send to you

Cheers
Neil
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6151719
I have 97, but if it will work send it to ngfschulz@yahoo.com
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6151724
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6151725
Testing 123
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6151727
Testing 345
678
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6151729
Testing '
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6151730
Testing ?
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6151732
Testing - _ / , ! ? @ *
0
 
LVL 4

Accepted Solution

by:
nmilmine earned 100 total points
ID: 6151891
Hi nschulz

Have sent a version in 97

Cheers
Neil

PS There seems to be lots of testing ??????
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6153540
Thanks Neil. Ive been avoiding activex as users arent too computer literate and its a pain explaining how to register control. I may look for some code to register control on first open. Nice sample,simple clean code.
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6160595
Hi nschulz,

I'd appriciate it very much if you could describe in few words how the solution is working.

nmilmine,
You are more than welcome to add your own explanation as well.

Thanx,

Nosterdamus
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6162585
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6162591
Hi nosterdamus:
Im near 300 hours on this application Im writing
and the progress bar will be added in at the very end for flash but its not a big deal for me right now. To date Ive got about 140 SQLs stuffed into modules and Im exporting 6 different file types from each of these so it will take some time to think about the easiest way to get the progress bar into these routines.I actually found some code to create and run a progress bar from the windows API but quite frankly its over my head (only been working with VBA for a year).Anyways thanks for posting your code, I will have a closer look at it when the time comes and If I use it Ill post you some points.
Norm
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6162595
PS EE still not reading quotation marks.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Some sers suddenly getting error popup msg 28 88
zero pad a access form field 2 15
Create tables in access db (2016)  using vba 13 41
Should I keep recordsets open? 3 23
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

776 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