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 |