Detecting View or Form in LS

In L/S, how would I test to see if I’m running a script from a form or a view? Seems I cannot get (evaluate) a viewname if I’m in a form…but from a view, it works OK.

Here’s some code:

Dim uidoc As NotesUIDocument

Set uidoc=workspace.CurrentDocument



Dim doc As NotesDocument



Set newdoc=New NotesDocument(db)



Dim uview As NotesUIView

Dim view As NotesView

Dim viewname As String

Set uview = workspace.CurrentView

viewname = uview.ViewName             < ?????



Messagebox viewname  'just to test



If viewname <> "" Then

Subject: Detecting View or Form in LS

workspace.CurrentView will be Nothing on a document, and workspace.CurrentDocument will be Nothing on a view.

Subject: Detecting View or Form in LS

Yes, that’s correct - if the view name is blank, you’re not in a view.

Subject: RE: Detecting View or Form in LS

So, why do I get an error “Object variable not set” when I execute this code from a Form, tring to evaluate if I’m in a form or a view?

Confused…

Subject: RE: Detecting View or Form in LS

See my post – compare the view to Nothing first before attempting to access any of its properties or methods. Same goes for the document.

Subject: Detecting View or Form in LS… GOT IT!!! THANKS!!!

Boy, am I dense…

Here’s what I did:

Dim session As New NotesSession

Dim db As NotesDatabase

Set db=session.CurrentDatabase

Dim workspace As New NotesUIWorkspace



If workspace.CurrentDocument Is Nothing Then

	Messagebox "View Mode"	

	Dim uview As NotesUIView

	Set uview = workspace.CurrentView

	Set collection = db.UnprocessedDocuments

	Set doc = collection.GetFirstDocument

	Set newdoc= New NotesDocument(db)

End If



If workspace.CurrentView Is Nothing Then

	Messagebox "Document Mode"

	Dim uidoc As NotesUIDocument

	Set uidoc=workspace.CurrentDocument

	Set doc=uidoc.Document

	Set newdoc= New NotesDocument(db)

End If



newdoc.form = "Burn-In\Bib Set Shipping Form"

newdoc.NameProg = doc.NameProg

.

.

.

.