I have an access database where I need to download a file daily from a website, and then use this file to do some calculations.
The issue that I'm running into is that the website requires a log-in. If I manually click "ok" to the log-in screen that pops up when the macro tries to download the data, then the macro and database runs fine. But what I'm ultimately planning on doing is to have this run on a schedule so I would need a way to "bypass" the log in screen. any ideas on how to do this?
I have included my code below.
Option Compare Database
Function Download_File(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte
'You can also set a ref. to Microsoft XML, and Dim oXMLHTTP as MSXML2.XMLHTTP
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the website
oXMLHTTP.Send 'send request '****** This is where I get the log in;
'Wait for request to finish
Do While oXMLHTTP.readyState <> 4
oResp = oXMLHTTP.responseBody 'Returns the results as a byte array
'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Set oXMLHTTP = Nothing
Sub downloadSetup(dl_link As String, savefile As String)
'Download tiny web server to the %TEMP% directory, use local copy of winzip to unzip
'Obviously in a real world application you'd want to bring your own unzipper
Download_File dl_link, savefile
'Run_Program "winzip", "-e -o %TEMP%\tinyweb.zip %TEMP%", INVISIBLE, Wait
Sub download_data(dl_folder As String, format_val As String, dl_date As Date)
Dim latest_date As Date
Dim file_date As String, link As String
latest_date = dl_date
If (Right(dl_folder, 1) <> "\") Then
dl_folder = dl_folder & "\"
file_date = Format(Year(latest_date), "0000") & Format(Month(latest_date), "00") & Format(Day(latest_date), "00")
link = "https://filedownloadlink.com/files/classification" & "/415?date=" & file_date & "&format=" & format_val
Call downloadSetup(link, dl_folder & product_grp & file_date & ".txt")