Microsoft KB Archive/209917

= ACC2000: Examples Using the Internet Transfer ActiveX Control =

Article ID: 209917

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q209917



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
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 2000.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. 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 from 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 Page
The following example uses the Internet transfer control with HTTP to create an HTML page based on Microsoft's home page, and to view the header information for the page.

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

 Start Microsoft Access and open the sample database Northwind.mdb or the sample project NorthwindCS.adp. Create a new form not based on any table or query in Design view with the following controls and properties:

Form: frmOpenURL

Caption: OpenURL Form

Command Button 1

Name: cmdWriteFile

Caption: Write to Disk

Command Button 2

Name: cmdGetHeader

Caption: Get Header

 On the Insert menu, click ActiveX Control. In the Insert ActiveX Control dialog box, select Microsoft Internet Transfer Control, version 6.0, and then click OK. Set the Internet control's Name property to axInetTran . On the View menu, click Code.</li> Type the following line in the Declarations section of the form's class module:

Dim objInet as Inet

</li>  Type or paste 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 </li> Save the frmOpenURL form, and open it in Form view.</li> 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 disk.

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 is transferred.</li> Click the Get Header button.

Note the message box that displays the header information from Microsoft's home page.</li></ol>

When using the OpenURL method of the Internet Transfer Control to download files on the Internet, sometimes only part of the file downloads. Microsoft has confirmed this to be a bug. This bug has been fixed in Visual Studio 97 Service Pack 2.

For additional information about the OpenURL method, click the article number below to view the article in the Microsoft Knowledge Base:

171828 FIX: INET OpenURL Method Doesn't Download Complete Files

Example 2 - Using FTP to Retrieve a File from an FTP Site
The 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 does 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.

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

<ol> Start Microsoft Access and open the sample database Northwind.mdb or the sample project NorthwindCS.adp.</li> Create a new form not based on any table or query in Design view with the following controls and properties:

Form: frmRetrieveFile

Caption: Retrieve FTP File

Command Button 1

Name: cmdGetFile

Caption: Get FTP File

Text Box 1

Name: txtFTPSite

Text Box 2

Name: txtFileName

</li> On the Insert menu, click ActiveX Control.</li> In the Insert ActiveX Control dialog box, select Microsoft Internet Transfer Control, version 6.0, and then click OK.</li> Set the Internet control's Name property to axFTP .</li> On the View menu, click Code.</li> Type the following line in the Declarations section of the form's class module:

Dim objFTP as Inet

</li>  Type or paste the following procedures for the form's Load event, for the Click event of the command button, and for the StateChanged event of the Internet transfer control: 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 </li> Save the frmRetrieveFile form, and switch it to Form view. Type ftp://ftp.microsoft.com in the txtFTPSite text box, type Dirmap.txt in the txtFileName text box, and then click the Get FTP File button.

After Dirmap.txt is transferred to drive C, a message box is displayed. You can check the C:\ directory to confirm that the Dirmap.txt file was created.</li></ol>

Additional query words: ole custom

Keywords: kbhowto kbinfo kbusage KB209917

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.