Download & Save MP3 via URL Link (1 Viewer)

vBeh?

New member
Local time
Today, 16:15
Joined
Mar 11, 2022
Messages
5
Hi,

I'm trying to find the easiest way to automatically download and save an MP3

Below is where I am up to and the approximate way I was hoping to approach this.

Any assistance would be really appreciated as I'm stuck. A lot of the solutions online seem very over engineered and complex and I'm sure there must be a more concise way.

Private Sub OnTimer()


'A checkbox which stops the on timer event running the commands below when unchecked
if [CheckGo] = false
Exit sub
End if

'stops process when there are no more records
if isnull (me.RecordID) Then
Exit sub
End if

'Declares instances of internet explorer (not sure if this is needed
Set ie = New InternetExplorer
ie.Visible = False

'Variables for URL, directory to save file and file name plus file type
Dim rURL, rFilePath, rFilename As String

'Values for variables
rURL = [rCurrentURL]
rFilePath = "D:\myfilepath\directory\"
rFilename = [rCurrentName] & ".mp3"

'Parses URL to ie
ie.navigate rURL

'Makes sure ie has fully loaded before next proceedure
While ie.Busy
DoEvents
Wend
While ie.Document.ReadyState <> "Complete"
DoEvents
Wend

-----------------------------------------------------------------------------------------------------------

This is the part that I cannot find a solution for
When I open the URL the audio file just plays automatically which I don't want or need to happen

What I could do with please is a section of code that will automatically download the audiofile to the file location I've declared and save this with the name specified

I need to avoid any sort of prompt that would need to be manually handled (IE a save confirmation notice)

I've looked online and can't find anything that seems to work

-----------------------------------------------------------------------------------------------------------


'A couple of form control fields are stamped to confirm completion of process
[DownloadComplete] = "Yes"
[DownloadStamp]= Now()

'The form moves forward one record

DoCmd.GoToRecord acDataForm, "MyForm", acNext

'End of process

End sub

'repeats
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:15
Joined
Oct 29, 2018
Messages
21,473
Hi. Welcome to AWF!

See if this article helps at all.

 

Gasman

Enthusiastic Amateur
Local time
Today, 16:15
Joined
Sep 21, 2011
Messages
14,306
Who cares?, if it works?
 

vBeh?

New member
Local time
Today, 16:15
Joined
Mar 11, 2022
Messages
5
Hi. Welcome to AWF!

See if this article helps at all.

Hi TheDBGuy

Thanks so much for taking the time to reply

I'm trying the latter of the suggested scripts from the link provided

The proceedure errors at the ".Send" line of the below with the message "Access Denied"

With objHTTP
.Open "GET", URL, False
.Send
If .Status = 200 Then
FileByte = .responseBody
End If
End With

I'm unsure why this is being a little outside of what I know anyway

Thank you again
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:15
Joined
Oct 29, 2018
Messages
21,473
Hi TheDBGuy

Thanks so much for taking the time to reply

I'm trying the latter of the suggested scripts from the link provided

The proceedure errors at the ".Send" line of the below with the message "Access Denied"

With objHTTP
.Open "GET", URL, False
.Send
If .Status = 200 Then
FileByte = .responseBody
End If
End With

I'm unsure why this is being a little outside of what I know anyway

Thank you again
Just to isolate the problem, try using a different URL (one that is publicly accessible). If you get the same error, then the problem is probably not with the website where you're trying to download the MP3 file from. Or, you could also try downloading an image or PDF file, instead of MP3, just to see if it makes a difference.
 

D_Walla

Member
Local time
Today, 16:15
Joined
Aug 1, 2021
Messages
32
In addition to the suggestions provided above, you may also try using a different method, like instead of:
Code:
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
use
Code:
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
But the API approach set out on theDBguy's blog post should download it for you without difficulty.
 

Users who are viewing this thread

Top Bottom