ACC97: Example Using the Internet Transfer ActiveX ControlLast reviewed: November 10, 1997Article ID: Q163653 |
The information in this article applies to:
SUMMARYModerate: Requires basic macro, coding, and interoperability skills. This article shows two examples using 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.
MORE INFORMATIONThe 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.
Example 1 - Using the OpenURL Method to Retrieve an HTML PageThe following example uses the internet transfer control with HTTP to create an HTML page based on Microsoft's World Wide Web home page, and to view the header information for the page.
1. Start Microsoft Access and open the sample database Northwind.mdb. 2. Create a new form not based on any table or query in Design view: Form: frmOpenURL -------------------------- Caption: OpenURL Form Command button: Name: cmdWriteFile Caption: Write to Disk Command button: Name: cmdGetHeader Caption: Get Header 3. On the Insert menu, click ActiveX control. 4. In the Insert ActiveX Control dialog box, select Microsoft Internet Transfer Control, version 5.0, and then click OK. 5. Set the internet control's Name property to axInetTran. 6. On the View menu, click Code. 7. Type the following line in the Declarations section of the form's class module: Dim objInet as Inet 8. Type the following procedures for the form's Load event and for the Click event of each command button: 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 9. Save the frmOpenURL form, and switch it to Form view. 10. Click the Write To Disk button. Use Windows Explorer or File Manager to verify that the file C:\Homepage.htm has been created on your hard drive. You can open the file in your Web browser to view the contents of Microsoft's home page. NOTE: No graphics appear on the page; only the text was transferred. 11. Click the Get Header button. Note the message box that displays the header information from Microsoft's home page on the World Wide Web. Example 2 - Using FTP to Retrieve a File from an FTP SiteThe following example uses the internet transfer control with FTP to retrieve a file called Dirmap.txt from Microsoft's FTP site. NOTE: The internet transfer control File Transfer Protocol will not work with some Internet proxy servers. If you do not have a direct connection to the Internet through an Internet Service Provider (ISP), verify that your proxy server supports FTP connections.
REFERENCESFor 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |