D.6. Enhanced CreateObject Function

The CreateObject function has had a major enhancement with an additional string parameter that allows you to specify the name of the server where the object resides. If you're writing client-server applications with remote servers, you should find this a powerful addition to your armory, as this short example demonstrates:

Dim sMainServer As String
Dim sBackUpServer As String

sMainServer = "NTPROD1"
sBackUpServer = "NTPROD2"

If IsOnline(sMainServer) Then
    CreateObject("Sales.Customer",sMainServer)
Else
    CreateObject("Sales.Customer",sBackUpServer)
End If

For information, see Reference entry "CreateObject Function" in Chapter 7.

Get VB & VBA in a Nutshell: The Language 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.