Lotus Notes FAQ Visit Our Sponsor!

How do you open a document in edit mode if it exists?

The following code will open in edit mode the first doc in the "UPref" view if it exists or create a new document if it doesn't exist. Use GetDocumentByKey on the view if you need to select a specific document first.

Dim session As New Notessession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument

Set db = session.CurrentDatabase
Set view = db.GetView("UPref")

On Error Resume Next
Set doc = view.GetFirstDocument
If doc Is Nothing Then
 Set uidoc = ws.ComposeDocument("","","UPref")
Else
 ws.OpenDatabase "","","UPref"
 ws.EditDocument
End If

Applies to Notes Versions: 4, 4.5, 4.6, 5
Last Modified: January 6, 1998