Private views

Hi,

I am using “Shared, private on first use” views to show information to a related @username, what is happening is that when I need to do some changes in the view (add a new column, a new formula, etc.) I must create a new view (with other name) otherwise the changes wont take effect.

The question is : How can I change a “Shared, private on first use” view in a way that this takes effect on the users ?

or

How can I delete users “Shared, private on first use” views ?

Thanks in advance,

Paulo

Subject: Private views

Below is a function you could use . . . maybe in the PostOpen event of the database?

Build an array containing the view name of each private view you need to delete, then call this function passing a handle to the NotesDatabase and the array of target view names. If you do use the PostOpen event of the database, you may need to close the UI database and re-open it after removing the private view(s).

hth,

dgg

Declare Function W32OSPathNetConstruct Lib “nnotes” Alias “OSPathNetConstruct” ( _

Byval nullPort As Long, _

Byval server As Lmbcs String, _

Byval filePath As Lmbcs String, _

Byval pathNet As Lmbcs String _

) As Integer

Declare Function W32NSFDbOpen Lib “nnotes” Alias “NSFDbOpen” ( _

Byval dbPath As Lmbcs String, _

hDb As Long _

) As Integer

Declare Function W32NSFDbClose Lib “nnotes” Alias “NSFDbClose” ( _

Byval hDb As Long _

) As Integer

Declare Function W32NIFFindPrivateDesignNote Lib “nnotes” Alias “NIFFindPrivateDesignNote” ( _

Byval hDb As Long, _

Byval noteName As Lmbcs String, _

Byval noteClass As Integer, _

noteID As Long _

) As Integer

Declare Private Function W32OSLoadString Lib “nnotes” Alias “OSLoadString” (_

Byval hModule As Long, _

Byval stringCode As Integer, _

Byval retBuffer As Lmbcs String, _

bufferLength As Integer _

) As Integer

Sub deletePrivateViews(pndbTarget As NotesDatabase, pvarViewNames As Variant)

On Error Goto errorHandler

Const NOTE_CLASS_VIEW = &H0008

Const ERR_VIEW_NOT_FOUND = 1028

Const ARRAY_FIXED = 8192

Const ARRAY_DYNAM = 8704

Const V_STRING = 8

Dim docDznNote As NotesDocument

Dim lngHDb As Long

Dim lngNoteID As Long

Dim intRetCode As Integer

Dim strErrMsg As String

Dim strPath As String * 512

Dim strViewName As String

Dim varViewNames As Variant

Select Case Datatype(pvarViewNames)

Case ARRAY_FIXED + V_STRING, ARRAY_DYNAM + V_STRING '// assign local variable and allow code to run

varViewNames = pvarViewNames

Case V_STRING

varViewNames = Split(pvarViewNames, “~+|+~”) '// force string into a single element array

Case Else '// raise an error

strErrMsg$ = "Parameter type " & Datatype(pvarViewNames) & ": " & Typename(pvarViewNames)

strErrMsg$ = strErrMsg$ & " is unsupported - a string or string array of target view names is expected"

Error 7501, strErrMsg$

End Select

'// Construct an API-friendly database path.

Call W32OSPathNetConstruct(0, pndbTarget.Server, pndbTarget.FilePath, strPath$)

'// Get a handle to the database.

intRetCode% = W32NSFDbOpen(strPath$, lngHDb&)

If Not(intRetCode% = 0) Then

Msgbox {Failed to obtain a handle to the target database - unable to remove private view.}, , “Failed to obtain a handle . . .”

Goto thisExit

End If

Forall vName In varViewNames

strViewName$ = vName

'// Attempt to access the private design note via API.

intRetCode% = W32NIFFindPrivateDesignNote(lngHDb&, strViewName$, NOTE_CLASS_VIEW, lngNoteID&)

If intRetCode% = 0 Then

Set docDznNote = pndbTarget.GetDocumentByID(Hex$(lngNoteID&))

If Not(docDznNote Is Nothing) Then

If docDznNote.HasItem(“$Collation”) Then '// just a precaution to make sure we actually got a -view- note

Call docDznNote.Remove(True)

Print {View “} & strViewName$ & {” removed . . .}

End If

End If

Else

Call getAPIErrorDesc(intRetCode%, strErrMsg$)

If intRetCode% = ERR_VIEW_NOT_FOUND Then '// in most cases, we would probably want to suppress this error completely

Msgbox {A private view titled “} & strViewName$ & {” was not found.}, , “Private view not found . . .”

Else

Msgbox {Unable to remove private view titled “} & strViewName$ & {” for the following reason:} _

& Chr(13) & “Encountered error " & intRetCode% & " (” & strErrMsg$ & “).”, , “Unable to remove private view . . .”

End If

End If

End Forall

thisExit:

If lngHDb& > 0 Then

Call W32NSFDbClose(lngHDb&) '// always try to close the db handle

lngHDb& = 0

End If

Exit Sub

errorHandler:

'// Note that this is just “generic” error-handling.

Msgbox "Error " & Err & ": " & Error$ & " encountered at line " & Erl & " of " & Getthreadinfo(1) & “.”, , “Error encountered . . .”

Print "Error " & Err & “: " & Error$ & " encountered at line " & Erl & " of " & Getthreadinfo(1) & " . . .”

Resume thisExit

End Sub

Private Sub getAPIErrorDesc(pintRetCode As Integer, pstrErrMsg As String)

'// +++ GLOBAL VARIABLES +++

'// Constants:

'//

'//

'// Class instances:

'//

'//

'// 08/09/2002 - Dallas Gimpel

'//

'// DESCRIPTION:

'// This sub takes the unmodified return code returned by an api call and “decodes” it

'// into a less cryptic error number. It then returns the text associated with the given

'// error number by making an api call which loads the text into a string variable. If

'// no text is returned for the given error, it defaults to “unknown error”.

'//

'// INPUT:

'// pintRetCode - Integer, the original return code as returned from the api call

'//

'// OUTPUT:

'// pintRetCode - Integer, modified by “Anding” the error mask to it to produce a “kinder & gentler” error

'// pstrErrMsg - String, the text of the error message as returned by the api

Const NULL_HANDLE = 0&

Const ERROR_MASK = &H3fff '// see globerr.h

Const BUFFER_SIZE% = 255

Const UNKOWN_ERR_DESC$ = “unknown error”

Dim intLength As Integer

pstrErrMsg$ = String$(BUFFER_SIZE + 1, 0)

pintRetCode% = pintRetCode% And ERROR_MASK

intLength% = W32OSLoadString(NULL_HANDLE, pintRetCode%, pstrErrMsg$, BUFFER_SIZE)

If intLength% > 0 Then '// if we got a valid error description back, use it

pstrErrMsg$ = Fulltrim(pstrErrMsg$)

Else

pstrErrMsg$ = UNKOWN_ERR_DESC

End If

End Sub