Google Answers Logo
View Question
 
Q: Access Question for Hammer ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Access Question for Hammer
Category: Computers > Programming
Asked by: bselltiz-ga
List Price: $10.00
Posted: 12 Mar 2003 11:05 PST
Expires: 11 Apr 2003 12:05 PDT
Question ID: 175223
Question for Hammer
I have an application that takes quite a long time to run some of it's
processes (queries, code ect).
I would like to display a pop up form showing that the computer is
processing. How can I display something along the lines of an animated
gif on my form, something such as a spinning hourglass or other little
animation.
Ideally it would be something that happened independent of Access
since Access will be so busy working on it's task. I am aware of using
the windows hourglass and don't want to go that route.
Thanks for any ideas.
Brian

Request for Question Clarification by hammer-ga on 12 Mar 2003 11:17 PST
The problem with shelling to something outside Access is getting rid
of it once you're finished. We'll probably be better off working from
inside Access. Let me play with it a bit and get back to you.

- Hammer

Clarification of Question by bselltiz-ga on 12 Mar 2003 19:24 PST
no problem, what ever you think is best.
Answer  
Subject: Re: Access Question for Hammer
Answered By: hammer-ga on 13 Mar 2003 08:17 PST
Rated:5 out of 5 stars
 
Okay, Brian! I built you an example of creating custom and using
progress bars in Access. You can download the sample at:
http://www.hammerdata.com/Google/progress.mdb

Limitations: This type of custom code only works when you have control
of what is going on and can use DoEvents. If you are in your own code,
you should be okay. If you kick off a long query, it is up to Access
when/if it relenquishes control. You may want to experiment with
putting a DoEvents call on a Timer if you have trouble in this case.

The example I provided has two forms. frmTest contains three buttons
that run different examples. frmProgress is the progress bar form
itself. I've included Public methods to make it reusable. I also gave
you methods to either show specific progress, or just spin, if you
don't know how long something will take. You can adjust these as
needed. Here are the form code modules. Note the DoEvents calls to
make sure the progress bar form gets a chance to repaint. Also note
that frmProgress has an OnTimer event:

----------------- frm Test ---------
Option Compare Database
Option Explicit

Private Sub Command0_Click()
Dim intOuterLoop As Integer
Dim lngInnerLoop As Long

    DoCmd.OpenForm "frmProgress"
    Forms("frmProgress").SetStatusText "Looping for the heck of it -
0% complete."
    For intOuterLoop = 1 To 100
        For lngInnerLoop = 0 To 10000000    ' Depending on your speed,
you may want to adjust this loop
            ' Killing time
        Next lngInnerLoop
    Forms("frmProgress").SetStatusText "Looping for the heck of it - "
& intOuterLoop & "% complete."
    Forms("frmProgress").SetProgress intOuterLoop
    DoEvents
    Next intOuterLoop
    DoCmd.Close acForm, "frmProgress", acSaveNo
    
End Sub

Private Sub Command1_Click()
Dim intOuterLoop As Integer
Dim lngInnerLoop As Long

    DoCmd.OpenForm "frmProgress"
    Forms("frmProgress").SetStatusText "Looping without knowing how
long it will take."
    Forms("frmProgress").SetProgress -1
    For intOuterLoop = 1 To 100
        For lngInnerLoop = 0 To 10000000    ' Depending on your speed,
you may want to adjust this loop
            ' Killing time
        Next lngInnerLoop
        DoEvents
    Next intOuterLoop
    DoCmd.Close acForm, "frmProgress", acSaveNo
    
End Sub

Private Sub Command2_Click()
Dim intOuterLoop As Integer
Dim lngInnerLoop As Long

    DoCmd.OpenForm "frmProgress"
    
    Forms("frmProgress").SetStatusText "First process with known
progress - 0% complete."
    For intOuterLoop = 1 To 100
        For lngInnerLoop = 0 To 10000000    ' Depending on your speed,
you may want to adjust this loop
            ' Killing time
        Next lngInnerLoop
    Forms("frmProgress").SetStatusText "Working on it - " &
intOuterLoop & "% complete."
    Forms("frmProgress").SetProgress intOuterLoop
    DoEvents
    Next intOuterLoop
    
    Forms("frmProgress").SetStatusText "Second process with unknown
endpoint."
    Forms("frmProgress").SetProgress -1
    For intOuterLoop = 1 To 100
        For lngInnerLoop = 0 To 10000000    ' Depending on your speed,
you may want to adjust this loop
            ' Killing time
        Next lngInnerLoop
        DoEvents
    Next intOuterLoop
    DoCmd.Close acForm, "frmProgress", acSaveNo
    
End Sub


---------- frmProgress ----

Option Compare Database
Option Explicit

Private intLoop As Integer
Private strProgress(8) As String

Public Sub SetStatusText(strMessage As String)

    ctlStatus.Caption = strMessage

End Sub

Public Sub SetProgress(intPercent As Integer)
' Pass -1 to spin the progress indicator without showing
' specific percentage progress
Dim strProgress As String

    If intPercent < 0 Then
        Me.TimerInterval = 1000
    Else
        Me.TimerInterval = 0
        If intPercent > 100 Then
            intPercent = 100
        End If
        strProgress = String(intPercent, "|")
        ctlProgress.TextAlign = 1   ' Left
        ctlProgress.Caption = strProgress
    End If

End Sub

Private Sub SetProgressSpin()

    ctlProgress.TextAlign = 4   ' Distribute
    
    ctlProgress.Caption = strProgress(intLoop)
    Me.Repaint
    DoEvents
    intLoop = intLoop + 1
    If intLoop > 8 Then
        intLoop = 1
    End If

End Sub

Private Sub Form_Load()

    strProgress(1) = "| | | | |"
    strProgress(2) = "| / / / |"
    strProgress(3) = "| - - - |"
    strProgress(4) = "| \ \ \ |"
    strProgress(5) = "| | | | |"
    strProgress(6) = "| / / / |"
    strProgress(7) = "| - - - |"
    strProgress(8) = "| \ \ \ |"

    intLoop = 1

    ctlStatus.Caption = ""
    ctlProgress.Caption = ""
    ctlProgress.TextAlign = 1   ' Left
    
End Sub

Private Sub Form_Timer()

    SetProgressSpin

End Sub

--------------------------------

Take a look at the sample mdb and let me know if you have questions!

- Hammer

Clarification of Answer by hammer-ga on 19 Mar 2003 04:44 PST
Brian,

Have you had a chance to download the sample project yet? I'd like to
remove it from my download area. Let me know. Thanks!

- Hammer
bselltiz-ga rated this answer:5 out of 5 stars
Excellent info as always - thanks again! :->

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy