' MS Word Basic Example ' This example gets the currently selected contact's first and last name. Public Sub GetNameExample() On Local Error GoTo ErrHandler Dim lReturn As Long Dim sMsg As String Dim pc As Object '*** prepare the connection If lReturn = 0 Then Set pc = CreateObject("AccComm.OAConnector") pc.ConnectTo = "oapbserver" pc.Sender = "msword" End If '*** load the selected contact If lReturn = 0 Then lReturn = pc.ExecuteCommand("LOADENTRY") If lReturn = 0 Then If Left(pc.Result, 3) <> "OK:" Then lReturn = -11 sMsg = "Command failed to execute(" & Format(lReturn) & ")" & vbCrLf & pc.Result End If Else If pc.ConnectionFailed Then sMsg = "Connection to the phone book failed." & vbCrLf & pc.ErrorDescription Else sMsg = "Error connecting to the phone book." & vbCrLf & pc.ErrorDescription End If End If End If '*** get the name If lReturn = 0 Then lReturn = pc.ExecuteCommand("GETNAME FIRST LAST") If lReturn = 0 Then If Left(pc.Result, 3) <> "OK:" Then lReturn = -11 sMsg = "Command failed to execute(" & Format(lReturn) & ")" & vbCrLf & pc.Result Else sMsg = pc.Result End If Else If pc.ConnectionFailed Then sMsg = "Connection to the phone book failed." & vbCrLf & pc.ErrorDescription Else sMsg = "Error connecting to the phone book." & vbCrLf & pc.ErrorDescription End If End If End If CleanUp: On Local Error Resume Next '*** display error message If Len(sMsg) > 0 Then Call MsgBox(sMsg, vbOKOnly, "Office Accelerator") End If Exit Sub ErrHandler: sMsg = "Word Basic Error: " & Format$(Err.Number) & vbCrLf & Err.Description lReturn = -11 Resume CleanUp End Sub