Solved

Progress Bar from Windows API

Posted on 2001-06-02
21
453 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

760 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

24 Experts available now in Live!

Get 1:1 Help Now