How to Automate the download of a file from a website

I have set up functionality within an Access database that will allow users to import data from a spreadsheet that the user has to download from our Supplier website.

In order to further streamline this process, is it possible to somehow automate the download from the supplier website?

Further information:  In order to download the information required, the user must go to the supplier website, input login details, select the correct options to bring them to the necessary page, to then populate date controls and select from a customer code list and finally to choose to export to Excel.

Is this possible, or would it be a better bet to ask the supplier if they could automate the delivery of this information in some way?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You should first ask the supplier if they allow automation of their site. In some cases, this would be a violation of their Terms of Use.

If they do provide automation, you'll often find that those methods are not easily used in Access - they often require you to issue web-centric calls to the site's automation engine, which Access often has difficulty doing.

If they don't provide automation, but have no problem with you doing this, then you can try using a Web Browser control on your Form. Here's the MSDN reference for the WebBrowser:
Gustav BrockCIOCommented:
thechrisrobertstooAuthor Commented:
Thanks Gustav, but I'm not trying to download either an image or a web page, I'm trying to run the export functionality that's built-in to the website.

LMConsulting:  That seems a little over-involved.  I already have the functionality to import the data once it has been downloaded.  I don't especially have a need to achieve the download via an Access form.  It could just be a script that gets run daily as a scheduled task.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Gustav BrockCIOCommented:
Oh, missed that part.

Then you'll have to put your browser in debug mode and study the calls and returned values during a session. Then find out how to mimic a session with the browser object.

I have done similar things in C# but have no idea how to achieve this in VBA.

thechrisrobertstooAuthor Commented:
Anyone able to help with this for VBA or with an independent schedule-able task?
1. Find an URL from which you want to download file - do it as /gustav told by watching the http calls (I'm using Firefox Live Http Headers add-on)

2. When you know URL, you can download file with:
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

Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal      As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function

Private Sub test()
    Debug.Print DownloadFile("", "C:\Data\file.txt")
End Sub

Open in new window

If you want to use user authorization, you can use it with "" form.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thechrisrobertstooAuthor Commented:
Thanks Slubek, that looks great.  There is an added difficulty in that the login screen has a variable code that also has to be typed in, which of course is an image.

Sorry, I'd forgotten that, I think I've probably wasted everyone's time.  Those image codes are designed to thwart this kind of automation, aren't they?
Gustav BrockCIOCommented:
Ha ha, yes they are.
However, you could automate the process up to the presentation of the image - and perhaps to continue after the manual typing.

thechrisrobertstooAuthor Commented:
Ok.  I appreciate all the help.  I'll try this out in while as I've been overtaken by another project.  I may restart some correspondence when I have time to work on this again.

I think that the best way is to ask your supplier for help. The files are rather strong secured, so I suppose you pay them rather big money and they should help you to get the files without CAPTCHA.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.