Sunday, 6 March 2011

Create a connection document

I often have to send out a button with some code to create a connection document in a local nab.  Here is the code.

        Messagebox "This action will automatically add Connection Documents to the <INSERT SERVER NAME> server if they do not already exist in your Personal Address Book.", 0 + 64, "New Connection Documents"
        Dim db As New NotesDatabase("" , "names.nsf")
        Dim view As NotesView
        Dim doc As NotesDocument
        Dim success As Variant
        Dim connect As NotesDocument
        Dim State As Integer
        State = 0
        Set view = db.GetView("Connections")
        Set doc = view.GetFirstDocument
        While Not (doc Is Nothing)
                If doc.optionalnetworkaddress(0) = "<INSERT SERVER IP ADDRESS>" Then
                        Goto Alert
                        Set doc = view.GetNextDocument(doc)
                End If
        Set connect = db.CreateDocument
        connect.form = "local"
        connect.type = "Connection"
        connect.destination = "<INSERT SERVER NAME>"
        connect.lanportname = "TCPIP"
        connect.connectiontype = "0"
        connect.ConnectionRecordFirst = "Normal"
        connect.optionalnetworkaddress = "<INSERT SERVER IP ADDRESS>"
        success = connect.ComputeWithForm( False, False)
        Call connect.Save(True,True)
        State = State + 1      
        Select Case State
        Case 0
                Messagebox "Your Personal Address Book already has a Server Connection Document for <INSERT SERVER NAME>; no new connection documents have been created." , 0 + 64 , "Finished!"
        Case 1
                Messagebox "Your Personal Address Book did not have a Server Connection document for <INSERT SERVER NAME>; a new connection document has been created." , 0 + 64, "Finished!"
        End Select

No comments:

Post a Comment