"Command is not available" error for EditDocument method of NotesUIDocument

I am trying to open a UIDocument in order to print it automatically. The document does not need to be edited or anything like that. I simply want to create the document, print it, and close it. My code is below:

Sub PrintForm(sdoc As NotesDocument, form As String)

    Set s = New NotesSession

    Set db = s.CurrentDatabase

    Set ws = New NotesUIWorkSpace



    Dim FormDoc As NotesDocument

    Dim fuidoc As NotesUIDocument



    Set FormDoc = db.CreateDocument()

    Call sdoc.CopyAllItems(FormDoc)

    FormDoc.Form = form

    FormDoc.CanEdit = "False"



    Set fuidoc = ws.EditDocument(False, FormDoc)

    Call fuidoc.Print(1)

    Call fuidoc.Close

End Sub

When running, I get a popup error: “Command is not available.” The error appears to be happening on the "Set fuidoc . . . " line (as it does not occur when this line is commented out) but the code otherwise executes as expected. I get my print and the lines of code after the error continue execution. Also, when I run in debug mode I do not get the error.

Any idea how to fix this problem?

Thanks.

Edward

Subject: “Command is not available” error for EditDocument method of NotesUIDocument

Instead of copyallitems, do this way:

Sub PrintForm(sdoc As NotesDocument, form As String)

Dim FormDoc As NotesDocument

Dim fuidoc As NotesUIDocument

Set s = New NotesSession

Set db = s.CurrentDatabase

Set ws = New NotesUIWorkSpace

'Set FormDoc = db.CreateDocument()

'Call sdoc.CopyAllItems(FormDoc)

Set FormDoc = sdoc

FormDoc.Form = form

FormDoc.CanEdit = “False”

Set fuidoc = ws.EditDocument(False, FormDoc)

Call fuidoc.Print(1)

Call fuidoc.Close

End Sub

This will work. But don’t know about the print statement. Please post whether you can be able to print, after your try.

Good luck.

Subject: RE: “Command is not available” error for EditDocument method of NotesUIDocument

I replaced the lines:

Set FormDoc = db.CreateDocument()

Call sdoc.CopyAllItems(FormDoc)

with the line:

Set FormDoc = sdoc

but still got the same error. Was this what you suggested?

Thanks.

Edward

Subject: RE: “Command is not available” error for EditDocument method of NotesUIDocument

yes.

Looks like you are not dimming ‘workspace’.

as you are using ‘set ws = new notesuiworkspace’, make sure you have this line too:

dim ws as notesUIWorkspace

or you can have one line instead of them both as

dim ws as New notesUIWorkspace

Subject: RE: “Command is not available” error for EditDocument method of NotesUIDocument

Sorry. The problem was unrelated. After the print I was refreshing my NotesUIView. Since I was not closing immediate Notes got confused on the ViewRefresh because it was still focussing on the NotesUIDocument. I changed the close to .Close(True) and this fixed the problem.

Thanks

Subject: RE: “Command is not available” error for EditDocument method of NotesUIDocument

Ok. As ‘True’ in close is an optional parameter for uidoc, I didn’t payt much attention to it as you are closing the doc. But that made the magic Ha? So After you open the document, your print seems working fine then. Thank you.