Help and Support
 

powered byLive Search

ACC97: Example Using the Internet Transfer ActiveX Control

Article ID:163653
Last Review:January 19, 2007
Revision:3.3
This article was previously published under Q163653
Moderate: Requires basic macro, coding, and interoperability skills.

On This Page

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

Back to the top

MORE INFORMATION

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.

Back to the top

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

Back to the top

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 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.
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: frmRetrieveFile
      --------------------------
      Caption: Retrieve FTP File

      Command button:
         Name: cmdGetFile
         Caption: Get FTP File
      Text box:
         Name: txtFTPSite
      Text box:
         Name: txtFileName
					
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 axFTP.
6.On the View menu, click Code.
7.Type the following line in the Declarations section of the form's class module:
       Dim objFTP as Inet
					
8.Type 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
					
9.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 C:\, a message box is displayed.

Back to the top

REFERENCES

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."

Back to the top


APPLIES TO
Microsoft Access 97 Standard Edition

Back to the top

Keywords: 
kbhowto kbprogramming kbusage KB163653

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.