I often use this to download a CSV to update data in a database. -
Option Compare Database
-
Option Explicit
-
Private 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
-
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
-
Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
-
-
Declare Function SystemParametersInfo Lib "user32" _
-
Alias "SystemParametersInfoA" (ByVal iAction As Long, _
-
ByVal iParam As Long, pvParam As Any, _
-
ByVal fWinIni As Long) As Long
-
-
'Purpose : Retreview text from a web site
-
'Inputs : sURLFileName The URL and file name to download.
-
' sSaveToFile The filename to save the file to.
-
' [bOverwriteExisting] If True overwrites the file if it exists
-
'Outputs : Returns True on success.
-
Function InternetGetFile(sURLFileName As String, sSaveToFile As String, Optional bOverwriteExisting As Boolean = False) As Boolean
-
Dim lRet As Long
-
Const S_OK As Long = 0, E_OUTOFMEMORY = &H8007000E
-
Const INTERNET_OPEN_TYPE_PRECONFIG = 0, INTERNET_FLAG_EXISTING_CONNECT = &H20000000
-
Const INTERNET_OPEN_TYPE_DIRECT = 1, INTERNET_OPEN_TYPE_PROXY = 3
-
Const INTERNET_FLAG_RELOAD = &H80000000
-
-
On Error Resume Next
-
DoCmd.Hourglass True
-
-
'Create an internet connection
-
lRet = InternetOpen("", INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
-
-
If bOverwriteExisting Then
-
If Len(Dir$(sSaveToFile)) Then
-
VBA.Kill sSaveToFile
-
End If
-
End If
-
-
'Check file doesn't already exist
-
If Len(Dir$(sSaveToFile)) = 0 Then
-
'Download file
-
lRet = URLDownloadToFile(0&, sURLFileName, sSaveToFile, 0&, 0)
-
If Len(Dir$(sSaveToFile)) Then
-
'File successfully downloaded
-
InternetGetFile = True
-
Else
-
'Failed to download file
-
If lRet = E_OUTOFMEMORY Then
-
Debug.Print "The buffer length is invalid or there was insufficient memory to complete the operation."
-
Else
-
Debug.Assert False
-
Debug.Print "Error occurred " & lRet & " (this is probably a proxy server error)."
-
End If
-
InternetGetFile = False
-
End If
-
End If
-
-
On Error GoTo 0
-
DoCmd.Hourglass False
-
End Function
-
0 15965 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rea Peleg |
last post by:
link to configuration file prevents user control download to internet
explorer
Hi
I have a simple web application which consists an opening html page with a
(windows form user) control
which...
|
by: Ilia Makarenko |
last post by:
Hi everyone!
I've got a problem with IIS 6.0 when downloading files with size > 4
Mb. So I am trying to download file in chunks, but it doesn't work.
Only pert of the file is downloaded (~6.5 of...
|
by: mphanke |
last post by:
Hi,
how can I connect to a restricted directory on a server and download a
file, if there is a newer version, than the one on the local file system?
Something like
...
|
by: user2008 |
last post by:
Hi all,
I want to track how many times visitor download file from my website,
for example, when visitor click on a download link, a ASPX page will be
requested, after that it will redirect to a...
|
by: bonita |
last post by:
If I add the code for user to download the file (e.g.
if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the
following timeout error:
Timeout expired. The timeout period elapsed prior to...
|
by: matt |
last post by:
I have used some free code for listing files for download, but I want to
send an email to the administrator when the file has been downloaded. I
have got some code in here that does it, but it will...
|
by: BiT |
last post by:
Hello,
I'm working right now on project in vb.net 2005 for my company, i need the
project to download file from the company web site.
In order to get the file i have to give the site address...
|
by: cypherkro |
last post by:
Hi
I have a requirement to automatically download a file using a WebBrowser control without having the "Download File" pop up windows display.
I cannot use Webclient!!
I am using VS2005, .net2...
|
by: vinodkus |
last post by:
dear sir/madam
I have to write a code for download file using asp. please help me
thanks in advance
|
by: vikassawant |
last post by:
Hi,
I m facing some critical problem for downloading 5mb file from server. Does anyone know?
How to reduce the time to download file from server using HTTP connection?
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |