Starting a download from MS Access

I want to start a download from an access application and then close the app and allow the download to complete.

Can anyone help me with the syntax.

Thanks in advance.
Clive BeatonAccess DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Gustav BrockCIOCommented:
You could use some kind of script controlling IE. Alternatively, let Access handle the download all by itself:

Download and save  a file

/gustav
Clive BeatonAccess DeveloperAuthor Commented:
Thanks Gustav, but I want  the app to start the download in the default browser, let the browser save the file wherever it normally does, then close itself.  

I can start the download by clicking on a label with a URL in the Hyperlink Address property, such as http://celebrantassist.com.au/downloads/TeamViewer_Setup.exe, which does exactly what I want.

But, once the download has started, I want the app to terminate itself without any user intervention.

Can you help?
Gustav BrockCIOCommented:
OK. Then all you should need is the command to close Access:

    Application.Quit acQuitSaveNone

/gustav
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!

Clive BeatonAccess DeveloperAuthor Commented:
The question is; where should i put this code?  If I put it on the On Click event of the label that contains the hyperlink, it creates the error:  Microsoft Access has stopped working...
Gustav BrockCIOCommented:
You could set the timer of the form in the click event:

    Me.TimerInterval = 1000

then move the quit command to the OnTimer event.

/gustav
MlandaTCommented:
How about just using ShellExecute to open the HTTP link. The  declaration goes to the top of a Module and you can call it from anywhere. This way, the link is opened in your default browser.
Declare Function ShellExecuteA Lib "shell32.dll" ( _
    ByVal hWnd As IntPtr, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Integer) As IntPtr

ShellExecuteA(Me.Handle, "open", "http://celebrantassist.com.au/downloads/TeamViewer_Setup.exe", "", "", 4)

Open in new window


More info: ACC: Start Files or Hyperlinks with Windows API ShellExecute()
Clive BeatonAccess DeveloperAuthor Commented:
Sorry, MlandaT,  I'm way out of my depth here.  Where do i Put the ShellExecute line of code?

Should it be in a function or sub, or an event procedure?

Where ever I try, it gives a compile error:  Expected =
MlandaTCommented:
In your Visual Basic editor, right click the project, and say Add -> Module as done on the screenshot here.Adding a moduleThen in that new module, insert the Declare statement in that file.The declare statementThen call the function in your button click.
Dim r As Long
r = ShellExecuteA(0, "open", "http://www.microsoft.com", 0, 0, 1)

ShellExecuteA Me.hwnd, "open", "http://www.microsoft.com", "", "", 1

Open in new window

However, I've just tried this in Windows 8 and the URL did not open... so a bit worried about reliability. I used to do this a lot on earlier versions of Windows and haven't had to do this in a while.
Clive BeatonAccess DeveloperAuthor Commented:
Oh, that's a bit of a pity.
MlandaTCommented:
So there is definitely an issue with UAC. http://weblog.west-wind.com/posts/2012/Dec/12/ProcessStart-and-ShellExecute-fails-with-URLs-on-Windows-8

Someone suggested this

ShellExecute(hwnd, "open", "explorer.exe", "[address here]", "", SW_SHOW);//Open the URL in IE
Gustav BrockCIOCommented:
Well, this works:
Private Sub LabelLink_Click()

    FollowHyperlink "http://filedb.experts-exchange.com/incoming/2015/04_w16/909314/ModernBox-1.0.1.zip"
    Me.TimerInterval = 1000

End Sub

Private Sub Form_Timer()

    Application.Quit acQuitSaveNone
    
End Sub

Open in new window

/gustav

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
Clive BeatonAccess DeveloperAuthor Commented:
Thanks, Gustav.  It worked perfectly.

Clive
Gustav BrockCIOCommented:
You are welcome!

/gustav
MlandaTCommented:
That's a really nice solution: https://msdn.microsoft.com/en-us/library/office/ff822080(v=office.14).aspx

Note that it's Office 2010+. Don't know about you... I still have a few people on 2007 :( But nice!
Clive BeatonAccess DeveloperAuthor Commented:
Hmmm.  That's a worry.
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
Microsoft Access

From novice to tech pro — start learning today.