Create and Cancel Network Connections Programmatically


You’d like to be able to connect to remote network devices from within your own Access applications. You know that you could do this manually, using Explorer or File Manager, but there must be some internal API for controlling these connections. Is there some way you can manage connections from within Access?


Windows provides a rich interface to its networking subsystem through its API. Many of the function calls are difficult, if not impossible, to call from VBA because of the language’s lack of pointer variable types. Some important calls, however, are quite simple to use, as you’ll see in this solution. The example form will demonstrate connecting to and disconnecting from remote devices (printers and drives) using common dialogs or using code with no user interface.

Load and run frmNetworkSample from 11-14.MDB. Figure 11-16 shows the form in use on a small Windows 2000 network. This sample form, demonstrating all the capabilities covered in this solution, does the following:

  • Retrieves the current username and computer name.

  • Walks through all 26 possible drive letters and displays any drive mappings connected to those drives.

  • Allows you to delete any of the displayed drive connections.

  • Provides a method for adding new connections, where you supply the four necessary parameters.

  • Uses the common dialogs for adding and canceling drive and printer connections. For example, Figure 11-17 shows the Disconnect ...

Get Access Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.