"Unable to change views in this context." error on View action button

I am trying to make a View action that changes the active UI view. When I try to run this action, I get the aforementioned error. Does anyone know of a way to work around this issue?

Thanks,

Brandon.

Code:

’ The viewFormulas list contains the default SELECT statements for each of

’ the view formulas that needs keyword filtering.

Dim viewFormulas List As String

’ The viewKeywords list contains the strings that should be appended to the

’ SELECT statements to yield the view formulas we need for each of the

’ keyword searches.

Dim viewKeywords List As String

Sub Initialize

’ snip init of viewFormulas and viewKeywords

End Sub

Public Sub DoLabelsClick( action As String )

Dim uiw As New NotesUIWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = uiw.CurrentDatabase.Database

’ See if a settings document for this user exists. If it

’ does, get a handle to it. If it doesn’t, create it

’ first, and then get a handle to it.

Dim configDoc As NotesDocument

Dim configView As NotesView

Set configView = db.GetView( “(Users)” )

Set configDoc = configView.GetDocumentByKey( session.UserName )

If configDoc Is Nothing Then

' Here, we need to make a new configuration document.

Set configDoc = db.CreateDocument

uniqueID = Evaluate( "@Unique" )

configDoc.ViewID = "(" + uniqueId( 0 ) + ")"

configDoc.Form = "Config\User Config"

configDoc.Name = session.UserName

Call configDoc.Save( 1, 1 )

End If

’ Determine the new view formula.

Dim currentView As NotesView

Dim newFormula As String

Set currentView = uiw.CurrentView.View

newFormula = viewFormulas( currentView.Name )

Select Case action

Case “General”:

newFormula = newFormula + viewKeywords( "General" )

Case “Agents”:

newFormula = newFormula + viewKeywords( "Agents" )

End Select

’ Create, build, and display the view.

Dim newView As NotesView

newViewName = configDoc.ViewID( 0 )

Set newView = db.GetView( newViewName )

If Not newView Is Nothing Then

' Delete the view if it exists.  We need to build it

' from scratch each time we want to call it up.

Call newView.Remove

End If

Set newView = db.CreateView( newViewName, newFormula, currentView )

Set dispView = db.GetView( newView.Name )

Call uiw.SetTargetFrame( “View Frame” )

Call uiw.CurrentDatabase.OpenView( dispView.Name, , , True )

Call uiw.ViewRebuild

End Sub