Here's a sample wininet function which returns a pdf file from a web server. You have to add the component to a form along with a textbox which you assign the URL to. The latter was to eliminate a problem . Good luck!
Private Function RetrievesampleReport(ByVal sPDFFileName As String) As Boolean
Dim sFileName As String
Dim sFilePath As String
Dim bKillFlag As Boolean
Dim sUser As String
Dim sPassword As String
Dim lFreeFile As Long
Dim sResponseFormat As String
Dim sUrl
On Error GoTo errHandler
Dim lMaxChunk As Long
sResponseFormat = "pdf" ' either "pdf" or "html"
' FORMAT THE URL
sUrl = "
sUrl = sUrl & "?user=" & sUser & "&password=" & sPassword
Text1.Text = sUrl
' The assignment of string to text box and use of that text box in the function was made a necesary by an error that the url was malformed.
' I found an aricle on the Internet which explained how to circumvent that problem.
Inet1.Protocol = icHTTPS
Inet1.OpenURL Text1.Text, icByteArray
DoEvents
Inet1.Execute Text1.Text
lMaxChunk = 102400
lFreeFile = FreeFile()
If Dir(sPDFFileName) > " " Then
bKillFlag = True
Kill (sPDFFileName)
bKillFlag = False
End If
Open sPDFFileName For Binary Access Write Lock Read Write As #lFreeFile
Do
Erase aResult()
DoEvents
lChunkSize = lMaxChunk
aResult = Inet1.GetChunk(lChunkSize, icByteArray)
If LOF(lFreeFile) > 0 Then
Seek lFreeFile, LOF(lFreeFile) + 1
End If
Put lFreeFile, , aResult
DoEvents
Loop Until lChunkSize < lMaxChunk
Close #lFreeFile
Inet1.Cancel
RetrievesampleReport = True
Exit Function
errHandler:
DoEvents
' err 35764 indicates last request is still processing so resume
' set a threshold for retries so we don't get in an infinite loop
If bKillFlag = True Then
MsgBox "The file could not be deleted. Looks like you did not close a previous acrobat reader window with a sample report in it!", vbInformation, "Close that window and try again"
RetrievesampleReport = False
Exit Function
End If
If Err = 35764 Then
Resume
End If
RetrievesampleReport = False
msgbox "An error occurred - yedda yedda " & error$
End Function