I’m trying to create a location document based on field values from a person document.
The code seems fine because there are no errors, it just doesn’t save. I’ve tried setting the field values both ways using extended class and ReplaceItemValue but see no difference. At first I thought the IsSummary was defaulting to False which is why I tried ReplaceItemValue. I know the code is working because if I use ws.EditDocument(True, ldoc) and click Save and Close, the field values are set correctly and the document saves. Without it though, there is no document. Please help.
Here’s the code.
Sub Click(Source As Button)
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim pab As NotesDatabase
Dim view As NotesView
Dim dc As NotesDocumentCollection
Dim ldoc As NotesDocument '--Location Document
Dim pdoc As NotesDocument '--Person Document
Dim datadir As String, upi As String
Set dc = ws.PickListCollection(PICKLIST_CUSTOM, False, "Test1/Home", "names.nsf", "People", _
"Home's Address Book - People", "Please select the account name and click OK")
If dc.Count = 0 Then
Msgbox "Operation cancelled ",48,"Problem"
Exit Sub
Else
Set pdoc = dc.GetFirstDocument
End If
datadir = s.GetEnvironmentString("Directory", True)
upi = Cstr(pdoc.EmployeeID(0))
While (Left(upi,1) = "0")
upi = Strright(upi,"0")
Wend
If Dir$(datadir + "\" + upi + ".ID") = "" Then
Msgbox "The ID for " + pdoc.LastName(0) + " was not found in " + datadir + Chr(10) + Chr(10) + _
"You will be prompted to save a copy of the ID the first time you switch to the new location ",64,"ID not found"
Else
End If
Set pab = s.GetDatabase("","names.nsf")
Set view = pab.GetView("Locations")
Set ldoc = view.GetDocumentByKey(pdoc.LastName,True)
If ldoc Is Nothing Then
Set ldoc = pab.CreateDocument
ldoc.Form = "Location"
Else
If Msgbox ("A location with the same name already exists. " + Chr(10) + Chr(10) + _
"Do you want to replace it?",4+32,"Duplicate found") = 7 Then
Exit Sub
Else
End If
End If
ldoc.LocationType = "0"
ldoc.Name = pdoc.LastName
ldoc.IMailAddress = pdoc.InternetAddress
ldoc.MailServer = pdoc.MailServer
ldoc.DefaultPassthruServer = ""
ldoc.EnabledPorts = "TCPIP"
ldoc.MailFile = pdoc.MailFile
ldoc.Domain = pdoc.MailDomain
ldoc.WebRetriever = "2"
ldoc.UseOSTz="1"
ldoc.UserID = datadir + "\" + upi + ".ID"
Call ldoc.Save(True, False)
End Sub