ACC97: Example Using the Internet Transfer ActiveX ControlID: Q163653
|
This article shows you two examples of how to use the Microsoft Internet
Transfer ActiveX Control that is included with the Microsoft Office
Developer Edition 97.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to the "Building
Applications with Microsoft Access 97" manual.
The Internet Transfer ActiveX Control provides you with access to the Internet and the World Wide Web using the two most common protocols: Hypertext Transfer Protocol (HTTP) and File Transfer Protocol (FTP). When you use the internet transfer control with HTTP, you can retrieve HTML documents from the Internet or an intranet. Using the internet transfer control with FTP, you can log on to FTP servers and download or upload files; the control supports many of the most common FTP commands such as GET, DIR, DELETE and CD.
Form: frmOpenURL
--------------------------
Caption: OpenURL Form
Command button:
Name: cmdWriteFile
Caption: Write to Disk
Command button:
Name: cmdGetHeader
Caption: Get Header
Dim objInet as Inet
Private Sub Form_Load()
' Set a reference to the internet transfer control.
Set objInet = Me!axInetTran.Object
End Sub
Private Sub cmdWriteFile_Click()
Dim b() as Byte
' Set the internet transfer control protocol and URL.
objInet.Protocol = icHTTP
objInet.URL = "HTTP://www.microsoft.com"
' Retrieve the HTML data into a byte array.
b() = objInet.OpenURL(objInet.URL,icByteArray)
' Create a local file from the retrieved data.
Open "C:\Homepage.htm" For Binary Access Write As #1
Put #1, , b()
Close #1
MsgBox "Done"
End Sub
Private Sub cmdGetHeader_Click()
' Set the internet transfer control protocol and URL.
objInet.Protocol = icHTTP
objInet.URL = "HTTP://www.microsoft.com"
' Open the HTML and display the header information.
objInet.openURL objInet.URL, icByteArray
MsgBox objInet.GetHeader
End Sub
Form: frmRetrieveFile
--------------------------
Caption: Retrieve FTP File
Command button:
Name: cmdGetFile
Caption: Get FTP File
Text box:
Name: txtFTPSite
Text box:
Name: txtFileName
Dim objFTP as Inet
Private Sub Form_Load()
' Set a reference to the internet transfer control.
Set objFTP = Me!axFTP.Object
End Sub
Private Sub cmdGetFile_Click()
Dim strSite As String
Dim strFile As String
strSite = Me!txtFTPSite
strFile = Me!txtFileName
objFTP.Protocol = icFTP
objFTP.URL = strSite
objFTP.Execute strSite, "Get " & strFile & " C:\" & strFile
End Sub
Private Sub axFTP_StateChanged(ByVal State As Integer)
' Display a message when the transfer is finished.
If State = 12 Then Msgbox "File Transferred"
End Sub
For more information about Internet Transfer ActiveX Control, search the
Help Index for "Internet Transfer control."
For more information about the Execute method, search the Help Index for
"Execute method (Internet Transfer Control)."
For more information about the StateChanged event, search the Help Index
for "StateChanged event."
Additional query words: ole custom
Keywords : kbusage kbdta AccCon KbVBA
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: August 2, 1999