Hi!
When I open a document I want to update some fields in it. The new values do I get from a view in the same database except from one value. That value comes from another database.
I can collect all the values and show them in a messagebox when I open the document. But when I do this code:
Call uidoc.FieldSetText(“DebAnslutning”,Str(sumAnslutning))
It says that I must be i editmode. I have given all users possibility to edit the document, but those who realy got this access is in a own role. In Querymodechange i look if the current user belong to this role, and if he don´t, he can´t go in editmode.
So, how do I fix, a user open the document, the document turns into edit mode, the values changes, document changes back to read mode with the new values and saves.
I’ll post all my code I have in Postopen:
Sub Postopen(Source As Notesuidocument)
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As notesDocument
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Dim DebAnslutning As Integer
Dim DebNatverk As Integer
Dim DebProgram As Integer
Dim DebOvrigt As Integer
Dim Debitering As Variant
Dim AntDeb As Integer
DebAnslutning = uidoc.FieldGetText(“DebAnslutning”)
DebNatverk =uidoc.FieldGetText(“DebNatverk”)
DebProgram = uidoc.FieldGetText(“DebProgram”)
DebOvrigt = uidoc.FieldGetText(“DebOvrigt”)
Debitering = Split(uidoc.FieldGetText(“debitering”), ", ",-1)
AntDeb = (Ubound(Debitering) + 1)
Dim db As NotesDatabase
Dim view As NotesView
Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
Dim viewdoc As NotesDocument
Dim sum As Integer
Dim sumAnslutning As Integer
Dim sumNatverk As Integer
Dim sumProgram As Integer
Dim sumOvrigt As Integer
sumAnslutning = 0
sumNatverk = 0
sumProgram = 0
sumOvrig = 0
Set db = session.CurrentDatabase
Set view = db.GetView( “Alla poster\Tjänster” )
For x = 0 To AntDeb-1
Set vc = view.GetAllEntriesByKey(Debitering(x))
Set entry = vc.GetFirstEntry()
Do Until entry Is Nothing
If entry.ColumnValues(1) = “Anslutning” Then
sumAnslutning = sumAnslutning + entry.ColumnValues(2)
End If
If entry.ColumnValues(1) = “Nätverk” Then
sumNatverk = sumNatverk + entry.ColumnValues(2)
End If
If entry.ColumnValues(1) = “Program” Then
sumProgram = sumProgram + entry.ColumnValues(2)
End If
If entry.ColumnValues(1) = “Övrigt” Then
sumOvrigt = sumOvrigt + entry.ColumnValues(2)
End If
Set entry = vc.GetNextEntry(entry)
Loop
Next
'Kontrollera PC-kostnad
Dim MaskinDb As New NotesDatabase( “”, “Maskiner.nsf” )
Dim MaskinDoc As NotesDocument
Dim MaskinView As NotesView
key = uidoc.FieldGetText(“Anr”)
Set MaskinView = MaskinDb.GetView (“Maskiner” )
Set MaskinDoc = MaskinView.GetDocumentByKey(key)
Dim sumPC As Variant
sumPC = Maskindoc.GetItemValue( “Kostnad” )
'Slut på PC-kostnadskontroll
Messagebox "PC-kost: " & sumPC(0) & Chr(13) & "Anslutning: " & sumAnslutning & Chr(13) & "Nätverk: " & sumNatverk & Chr(13) & "Program: " & sumProgram & Chr(13) & "Övrigt: " & sumOvrigt, “Riktiga värden”
Call uidoc.FieldSetText(“DebAnslutning”,Str(sumAnslutning))
Call uidoc.FieldSetText(“DebNatverk”,Str(sumNatverk))
Call uidoc.FieldSetText(“DebProgram”,Str(sumProgram))
Call uidoc.FieldSetText(“DebOvrigt”,Str(sumOvrigt))
End Sub
Thanks for your help!
best regards
Henrik