Progress Bar for Download

N

NevilleT

Just about created an automatic upgrade function to check if a new version of
the program is available, download and install it. I am downloading a file
from the Internet using:

Public Declare Function URLDownloadToFile Lib "urlmon" Alias
"URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long _
) As Long

lngRetVal = URLDownloadToFile(0, strURL, strNewFileNameIncPath, 0, 0) '
Download the new file

All works fine however the download takes a few minutes. What I would like
to do is to display a progress bar. Has anyone seen this done in Access?
 
B

BTU_needs_assistance_43

-Create a new form and call it "Progress"
-Create an Option Group or "frame" that runs a little wider and taller than
you want your progress bar to be and name it "FrameProgress"
-Name the word box with the option group "Caption"
-Create a lable above the frame with the message you want displayed while
loading
-Create a lable inside the frame thats a small distance inside the frame,
make the background normal, change its color to red or blue or whatever color
you want the bar to be, make sure it is sized to just inside the option group
frame, and name it "LabelProgress"
-Bring up the code for your progress form and place this code in it
Private Sub UserForm_activate()
Call Command6_Click
End Sub
-Then in the form whose operation you want a progress bar for, bring up its
code and paste the following at the beginning of the operations you want the
progress bar for

Dim PctDone As Single
DoCmd.OpenForm "Progress"
PctDone = (Equation For determining your percentage)
With Progress_Bar_Form
.Caption = Format(PctDone, "0%")
.LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
DoEvents

-Place the rest of your code here

-Place this after the opertaions you want to check the progress of

DoCmd.Close
MsgBox "Finished Loading"

-Done!

This will work best if you have a For i = 1 to "Some Value" statement so
that each time you get to Next i your percentage will update. Baring that,
you can at different points in your code set the value of PctDone to some
percentage and re-set the frame width to reflect that adjustment. It'll take
a little work with the numbers but will work.
 
S

Stuart McCall

NevilleT said:
Just about created an automatic upgrade function to check if a new version
of
the program is available, download and install it. I am downloading a
file
from the Internet using:

Public Declare Function URLDownloadToFile Lib "urlmon" Alias
"URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long _
) As Long

lngRetVal = URLDownloadToFile(0, strURL, strNewFileNameIncPath, 0, 0)
'
Download the new file

All works fine however the download takes a few minutes. What I would
like
to do is to display a progress bar. Has anyone seen this done in Access?

The problem you'll run into with anyone's progress bar is that they need to
be regularly updated by the function doing the work (or using a timer -
ugh!), and URLDownloadToFile won't do it for you. It will call a callback
function, but callbacks tend to cause trouble with the Access VBA
environment. Not worth the trouble for a simple 'busy' dialog. After all,
all the user needs to know is that a download is taking place and that the
program hasn't 'hung'. You could however try to find a 'bounce bar' (a la
the windows startup screen) form or control via Google. The advantage of
this type of dialog is that it doesn't need to know the file size and
doesn't need updating.I have one of these but it's tied in to a large app at
the moment. I've been meaning to break it out and make a download available
on my site (which Jack Leach kindly pointed you to). Maybe this is the right
time to do that, but if I do it won't be till at least Sunday.
 
N

NevilleT

Lots of good information here. Thanks guys. I think Stuart has hit on the
same problem I came up against in the refresh. Don't want to tie the system
up with a timer or running continuous updates. Will continue to play with it
and see what I come up with. If it is useful I will post it. Also check
back after Sunday to see if Stuart was able to post another option.

Thanks guys
 
S

Stuart McCall

NevilleT said:
Lots of good information here. Thanks guys. I think Stuart has hit on the
same problem I came up against in the refresh. Don't want to tie the
system
up with a timer or running continuous updates. Will continue to play with
it
and see what I come up with. If it is useful I will post it. Also check
back after Sunday to see if Stuart was able to post another option.

Thanks guys
<snip>

It's there ready to download as of now:

http://www.smccall.demon.co.uk/Downloads.htm#BounceBarForm
 
N

NevilleT

Hi Stuart

Thanks for the bounce bar. Tried it out without success. Created a form in
your database with a label and a button and put in the following code

Private Sub Command0_Click()
Dim intcounter As Integer
WaitForm True
Do While intcounter < 10000
intcounter = intcounter + 1
Me.Label1.Caption = intcounter
Me.Repaint
Loop
WaitForm False
End Sub

The bounce just keeps going and the counter label is not refreshed. Am I
doing something wrong?
 
S

Stuart McCall

NevilleT said:
Hi Stuart

Thanks for the bounce bar. Tried it out without success. Created a form
in
your database with a label and a button and put in the following code

Private Sub Command0_Click()
Dim intcounter As Integer
WaitForm True
Do While intcounter < 10000
intcounter = intcounter + 1
Me.Label1.Caption = intcounter
Me.Repaint
Loop
WaitForm False
End Sub

The bounce just keeps going and the counter label is not refreshed. Am I
doing something wrong?
<snip>

That's almost exactly what I used as a test rig. Hmm. I'll re-create what
you did and see what happens. This'll have to be later today (it's noon here
& I'm out till about 7pm).

I'll keep you posted...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top